Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

 

<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?

  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...