【发布时间】:2013-07-05 11:03:20
【问题描述】:
有人知道在使用 Linq 时如何获取 Obsolete 属性吗?
我正在做 NDepend 但无论如何我想进行查询并从应该被“弃用”的方法中获取所有过时的属性
Obsolete["I WANT THIS STRING"]
【问题讨论】:
-
在 LINQ/C# 中每个反射还是 CINQ/NDepend?
-
CLinq/NDepend。如果可以的话
有人知道在使用 Linq 时如何获取 Obsolete 属性吗?
我正在做 NDepend 但无论如何我想进行查询并从应该被“弃用”的方法中获取所有过时的属性
Obsolete["I WANT THIS STRING"]
【问题讨论】:
我相信你正在寻找这样的东西
from type in YourAssembly
from p in type.GetProperties()
from m in type.GetMembers()
let propertyAttributes = p.GetCustomAttributes(true)
let methodAttributes = m.GetCustomAttributes(true)
where propertyAttributes.Any(a => a.GetType() == typeof(ObsoleteAttribute))
|| methodAttributes.Any(a => a.GetType() == typeof(ObsoleteAttribute))
select new type;
它查询程序集中的所有类型,并选择那些具有 ObsoleteAttribute 的属性或方法的类型。
【讨论】: