Ok, also lerne ich über Generika und ich versuche, dieses Ding laufen zu lassen, aber es hält mich den gleichen Fehler. Hier ist der Code:Nicht-statische Methode erfordert ein Ziel in 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;
}
Danke, das war genau das, was ich gesucht habe ... –