Something which implements the ICustomAttributeProvider
interface will allow you to get custom attributes that have been applied to it via the GetCustomAttributes
method. As I understand it, a custom attribute is basically a special class (ending in "Attribute" and extending the Attribute
class) that is created to be applied to something like a method or class using the appropriate syntax ([FooAttribute]
just before the method/class/etc. in C#, for example). But if that is a custom attribute, what is a non-custom attribute? I used to think that attributes that were bundled with .NET were non-custom, but GetCustomAttributes
even returns me attributes like System.ThreadStaticAttribute
, which are very core to the .NET framework.
Is there such a thing as a non-custom attribute, or is "custom attribute" just a tautology?
Everything that derives from Attribute
is a custom attribute.
"Attribute" is a generic term. Objects in the real world have innumerable attributes. Classes, members and parameters all have attributes that we can describe -- names, types, accessors, number of members, inheritance information, etc.
Custom attributes are things that we tack on -- aspects that we want to associate and use to describe, but which are not intrinsic.
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