首页 > Windows开发 > 详细

C# 获取传入对象的所有属性名称

时间:2015-05-05 19:34:42      阅读:260      评论:0      收藏:0      [点我收藏+]
C# 获取传入对象的所有属性名称




 prolist p1 = new prolist();
             List<String> lt = getattr<prolist>(p1); 
//使用泛型,返回传入对象的属性,名称
public List<String> getattr<T>( T dx )
        {
            List<String> ls = new List<String>();
            Type types = dx.GetType();
            foreach (var p in types.GetProperties())
            {
             //   p.PropertyType
                ls.Add(p.Name);
            }
            return ls;


        }
    }
//实体对象
    public class prolist
    {
        private string _pid = "0";
        private string _pmoney = "0";
        public string pid
        {
            set { this._pid = value; }
            get { return this._pid; }
        }




        public string pmoney
        {
            set { this._pmoney = value; }
            get { return this._pmoney; }
        }
    }

C# 获取传入对象的所有属性名称

原文:http://blog.csdn.net/wangzhiqiang123456/article/details/45506019

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