您的位置:首页 > 编程语言 > C#

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

2015-05-05 18:21 323 查看
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; }

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: