0

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)
}
Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
k0ntrol
  • 17
  • 4
  • Your question is (definitely) a duplicate of [How do I use reflection to call a generic method?](https://stackoverflow.com/questions/232535/how-do-i-use-reflection-to-call-a-generic-method) – Ben Voigt Oct 30 '20 at 21:27
  • 1
    This looks like C# except for the missing `class` keyword on your definition of `Person`, is it? – Ben Voigt Oct 30 '20 at 21:28

0 Answers0