【发布时间】:2011-07-27 08:31:03
【问题描述】:
有没有办法根据对象的名称获取对象属性的值?
例如,如果我有:
public class Car : Vehicle
{
public string Make { get; set; }
}
和
var car = new Car { Make="Ford" };
我想编写一个方法,我可以在其中传递属性名称并返回属性值。即:
public string GetPropertyValue(string propertyName)
{
return the value of the property;
}
【问题讨论】:
标签: c# asp.net reflection