This question already has an answer here:
I'm trying to call a method which expects a generic type:
private Dictionary<string, ObjectComparerItem> GetDifferences<T>(T old, T actual) where T : class
{
}
I'm iterating through properties of a class and I would like to call this method passing the type of the property as the generic type T:
var properties = old.GetType().GetProperties();
foreach (var property in properties)
{
var obj = old.GetType().GetProperty(property.Name).GetValue(old);
var obj2 = actual.GetType().GetProperty(property.Name).GetValue(actual);
Type T2 = property.GetType();
var diffs = GetDifferences<T2>(obj, obj2);
}
PS: I've posted only a snippet of the code.
Aucun commentaire:
Enregistrer un commentaire