动态 获取实例中某个属性的值

 

///obj  实体

///property 属性名称

 public static object get(object obj, string property)     {   
return obj.GetType().InvokeMember(property, System.Reflection.BindingFlags.GetProperty, null, obj, null);
}


方法二
propertys = obj.GetType().GetProperty(property );
if (propertys != null)
return propertys.GetValue(obj, null);
else
throw new Exception(obj.GetType().FullName + "没有此属性" + ps[index]);

原文地址:https://www.cnblogs.com/kaixinmenghuan/p/2637988.html