Fre*_*örk 15
我假设你在运行时拥有属性的名称; 不是在编码时......
假设您的类名为TheClass,它有一个名为TheProperty的属性:
object GetThePropertyValue(object instance)
{
Type type = instance.GetType();
PropertyInfo propertyInfo = type.GetProperty("TheProperty");
return propertyInfo.GetValue(instance, null);
}
Run Code Online (Sandbox Code Playgroud)