Suppose I have a Person class that looks like this:
Person
{
public string Name {get; set;}
public string Age {get; set;}
}
And I have a method that takes a type T and a string as parameters
someMethod<T>(Action<T> someAction, string propertyName)
Is there a way to do something like this for each of a Person instance's property
Person p = new Person(){};
foreach(var propInfo in p.GetType().GetProperties())
{
someMethod<propInfo.PropertyType>(someAction, propInfo.Name)
}
Aucun commentaire:
Enregistrer un commentaire