Anyone knows how to get the Obsolete attribute when using Linq?

I'm doing NDepend but anyways I want to make a query and get all the obsolete attributes from the methods that are supposed to be "deprecated"

Obsolete["I WANT THIS STRING"]

有帮助吗?

解决方案

I believe something like this is what you are looking for

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;

It queries all types in an assembly and selects those which have properties or methods with the ObsoleteAttribute.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top