C#怎么获取object对象的属性值 (转)
The code is like this:
main()
{
Car car = new Car();
var value = GetPropertyValue(car, "name");
}
public static object GetPropertyValue(object info, string field)
{
if (info == null) return null;
Type t = info.GetType();
IEnumerable<System.Reflection.PropertyInfo> property = from pi in t.GetProperties() where pi.Name.ToLower() == field.ToLower() select pi;
return property.First().GetValue(info, null);
}

浙公网安备 33010602011771号