I have couple of domain objects something like:
public class Person()
{
public int age { get; set; }
public string city{ get; set; }
}
public class Company()
{
public string name{ get; set; }
public string address{ get; set; }
}
I have another class which calls the MyMethod as mentioned below.
public class CallTest()
{
Person p= new Person{age=10,city="dd"};
Company c= new Company{name="mynae",address="myaddress"};
MyMethod(p);
MyMethod(c);
}
mi.Name gives me the property name. But how do I get the property value?
public class MyMethod(object obj)
{
Type t = obj.GetType();
PropertyInfo prop = t.GetProperty("Items");
foreach (MemberInfo mi in t.GetMembers())
{
if (mi.MemberType == MemberTypes.Property)
{
var x = mi.Name;
}
}
}