From Java to C#: A Developers Guide

By convention, attribute class names are post-pended with ' Attribute ' (we have named our attribute classes Author Attribute , StatusOfClass Attribute , and Buggy Attribute ). This is not compulsory, but it is conventional and highly recommended.

You might have realized that when using the three attributes as attribute specifications in MyClass.cs , I used the shortcut Author instead of AuthorAttribute , and Buggy instead of BuggyAttribute . The C# compiler automatically searches for the AuthorAttribute class when it encounters ' Author ' in an attribute specification. [3]

[3] It is possible to write two separate attribute classes “ one by the name of AuthorAttribute , and the other called Author . In such cases, ambiguity will arise when ' Author ' is used in attribute specifications. There will be a compilation error in such cases. Nevertheless, you shouldn't be writing attribute classes with such confusing names. Stick to naming all your custom attribute classes Something Attribute .

You can replace the [Author] attribute tag in attribute specifications with [AuthorAttribute] with no consequences. C# gives you this flexibility.

This code:

6: [ Author ("Mok","21 Dec 02")] 7: public void DoSomething(){ 8: // some code 9: }

and this:

6: [ AuthorAttribute ("Mok","21 Dec 02")] 7: public void DoSomething(){ 8: // some code 9: }

are therefore equivalent.

Категории