【发布时间】:2016-12-22 00:06:57
【问题描述】:
我正在尝试获取一个类中的属性列表,其中属性标记有装饰器 [Ignore] (SQLite.Net),尽管我相信这个问题适用于任何装饰器。
var ignored = typeof(T)
.GetType()
.GetProperties().Where(p =>
p.GetCustomAttributes<SQLite.Net.Attributes.IgnoreAttribute>())
.ToList();
我尝试了各种组合——这里的组合甚至无法编译,但访问 p.CustomAttributes 集合可以;但是,它不会返回正确的属性。为了完整起见,这里是 T 中的属性:
private ProductCategory _category;
[Ignore]
public ProductCategory Category
{
get { return _category; }
set
...
请有人在这里指出正确的方向 - CustomAttributes 甚至是寻找这个的正确位置吗?
【问题讨论】:
标签: c# .net sqlite reflection properties