I 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);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…