物业名称和需要它的价值 [英] Property Name and need its value
本文介绍了物业名称和需要它的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个属性的名称,需要一类中找到它的价值,是什么让这个值的最快方法是什么?
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?
推荐答案
我在做,你必须在运行时属性的名称的假设;而不是编码...
I am making the assumption that you have the name of the property in runtime; not while coding...
让我们假设你的类被称为theClass描述,它有一个名为利人属性:
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);
}
这篇关于物业名称和需要它的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文