首页 > 其他 > 详细

获取一个类指定的属性值

时间:2018-11-24 20:13:06      阅读:204      评论:0      收藏:0      [点我收藏+]
        /// <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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!