【发布时间】:2015-02-11 15:11:11
【问题描述】:
我有一个类,它有很多属性,有些属性有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) 的?
-
所有可浏览@Selman22的属性
标签: c# properties attributes system.reflection