加载中…
个人资料
疯狂才子
疯狂才子
  • 博客等级:
  • 博客积分:0
  • 博客访问:2,937
  • 关注人气:30
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

C#如何获取object对象的属性值

(2013-07-15 20:12:19)
标签:

object对象

属性值

c

分类: C#-Asp.Net

C#如何获取object对象的属性值

  /// <summary>
     /// 获取一个类指定的属性值
      /// </summary>
      /// <param name="info">object对象</param>
      /// <param name="field">属性名称</param>
      /// <returns></returns>
        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);
        }

 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有