ठीक है, इसलिए मैं जेनेरिक के बारे में सीख रहा हूं और मैं यह चीज़ चलाने की कोशिश कर रहा हूं, लेकिन यह मुझे एक ही त्रुटि कह रहा है। कोड यह रहा:गैर-स्थैतिक विधि को PropertyInfo.SetValue
public static T Test<T>(MyClass myClass) where T : MyClass2
{
var result = default(T);
var resultType = typeof(T);
var fromClass = myClass.GetType();
var toProperties = resultType.GetProperties();
foreach (var propertyInfo in toProperties)
{
var fromProperty = fromClass.GetProperty(propertyInfo.Name);
if (fromProperty != null)
propertyInfo.SetValue(result, fromProperty, null);
}
return result;
}
धन्यवाद, कि मैं के लिए बस की तलाश थी ... –