Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom vs. non-custom attributes?

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?

like image 373
Jez Avatar asked Nov 14 '12 21:11

Jez


1 Answers

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.

like image 136
Jay Avatar answered Sep 23 '22 02:09

Jay