1

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

jason
  • 236,483
  • 35
  • 423
  • 525
Khiem-Kim Ho Xuan
  • 1,301
  • 1
  • 22
  • 45

1 Answers1

1

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.

Zache
  • 1,023
  • 6
  • 14