/// <summary> /// 获取一个类指定的属性值 /// </summary> /// <param name="info">object对象</param> /// <param name="field">属性名称</param> /// <returns></returns> public static object GetPropertyValue(object info, string field) { try { 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); } catch (Exception ex) { string msg = ex.Message.ToString(); return null; } }
转载于:https://www.cnblogs.com/zzlblog/p/10013193.html
最后
以上就是欢呼招牌最近收集整理的关于获取一个类指定的属性值的全部内容,更多相关获取一个类指定内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复