【问题标题】:Get Obsolete attribute using Linq使用 Linq 获取过时的属性
【发布时间】:2013-07-05 11:03:20
【问题描述】:

有人知道在使用 Linq 时如何获取 Obsolete 属性吗?

我正在做 NDepend 但无论如何我想进行查询并从应该被“弃用”的方法中获取所有过时的属性

Obsolete["I WANT THIS STRING"]

【问题讨论】:

标签: c# linq ndepend


【解决方案1】:

我相信你正在寻找这样的东西

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 的属性或方法的类型。

【讨论】:

    猜你喜欢
    • 2020-11-04
    • 1970-01-01
    • 2012-07-07
    • 1970-01-01
    • 1970-01-01
    • 2021-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多