当前位置: 代码迷 >> C# >> C# 获取传到对象的所有属性名称
  详细解决方案

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

热度:86   发布时间:2016-05-05 03:54:15.0
C# 获取传入对象的所有属性名称
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; }
        }
    }
  相关解决方案