我有一个有很多属性的类,有些属性有Browsable
属性。获取Browsable属性的所有属性
public class MyClass
{
public int Id;
public string Name;
public string City;
public int prpId
{
get { return Id; }
set { Id = value; }
}
[Browsable(false)]
public string prpName
{
get { return Name; }
set { Name = value; }
}
[Browsable(true)]
public string prpCity
{
get { return City; }
set { City= value; }
}
}
现在使用Reflection
,我怎么能滤除具有Browsable attributes
的属性?在这种情况下,我只需要获得prpName
和prpCity
。
这是我到目前为止尝试过的代码。
List<PropertyInfo> pInfo = typeof(MyClass).GetProperties().ToList();
但这选择所有的属性。有没有什么办法可以过滤只有Browsable attributes
的房产?
你想拥有可浏览所有属性, 对?或者只有Browsable(true)的那些? – 2015-02-11 15:20:37
所有可浏览的属性@ Selman22 – 2015-02-11 15:27:46