Can someone please give me an example of using Attribute.isDefined() to check if a particular custom attribute has been applied to a given class?
I've checked msdn, but only see possiblities for attributes applied to assemblies, members etc. I'm also open to alternative methods for achieving the same thing!
There doesn't seem to be an overload of Attribute.IsDefined
that takes a Type
.
Instead, You can call Type.GetCustomAttributes
:
if (typeof(SomeClass).GetCustomAttributes(typeof(SomeAttribute), false).Length > 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With