I have a name of a property and need to find its value within a Class, what is the fastest way of getting to this value?
See Question&Answers more detail:osI have a name of a property and need to find its value within a Class, what is the fastest way of getting to this value?
See Question&Answers more detail:osI am making the assumption that you have the name of the property in runtime; not while coding...
Let's assume your class is called TheClass and it has a property called TheProperty:
object GetThePropertyValue(object instance)
{
Type type = instance.GetType();
PropertyInfo propertyInfo = type.GetProperty("TheProperty");
return propertyInfo.GetValue(instance, null);
}