Question

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"]

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top