Strange behaviour with Attribute inheritance

rbulph

Junior Contributor
Joined
Feb 17, 2003
Messages
397
If I define a custom attribute with "Attribute" at the end of its name, I can use that attribute without putting "Attribute" at the end of its name, as follows:

Code:
<AttributeUsage(AttributeTargets.All)> Public Class ContreAttribute
    Inherits Attribute
   
End Class
<Contre()> Public Class ABCAttribute

End Class

I was rather surprised to see that the above doesn't generate any errors. It's not a problem, but I'm just wondering if it's part of a wider rule that I should know about or whether it just applies for Attributes. Anyone know?
 
This is correct behavior. It is just abbreviated syntax to make code look cleaner. Rather than having "attribute" inside every attribute tag, your code can read and look more concise.

Suffixing attribute classes with "Attribute" is a special naming convention honored by C# and VB.
 
Back
Top