What using C # attributes with the attribute suffix?

I am looking for C # code that applies several LINQ to SQL attributes with attribute suffix, for example. ColumnAttribute instead of the usual Column , which I use to use. Is there any reason besides verbosity to do this?

+4
source share
7 answers

There is no semantic difference. Probably the one who wrote the code simply preferred this notation.

It is also possible that the code was automatically generated using the tool. Code generation tools usually don't bother to remove an attribute bit from an attribute type name.

+6
source

The attribute is called ColumnAttribute . The compiler simply provides syntactic sugar so you can specify them without an attribute suffix.

There is no practical difference.

+3
source

Most attributes end with the word Attribute, including ColumnAttribute, CLSCompliantAttribute, and SerializableAttribute. The compiler allows you to exclude the last word of Attribute. It is the programmer's choice whether to add attributes to such names or not.

The attribute suffix, however, is just conditional: it is perfectly correct, although unusual, to define an attribute, for example, as follows:

  [AttributeUsage(AttributeTargets.All)] public class Foo : Attribute { } 

same as, for example, to define an exception called Throwable.

+3
source

No, it's just a style decision. However, if you are looking for code generated using CodeDOM, you are expected to have a suffix because the C # code generator will store the full name of type ___Attribute when adding an attribute.

+2
source

They are syntactically the same. AFAIK there is no reason for this if this person was not familiar with the fact that syntactic sugar in C # automatically adds the suffix "Attribute" when adding an attribute through square brackets.

+1
source

Column is simply an alias of ColumnAttribute and is syntactically identical in functionality and allowed by the compiler in any form. Some people prefer to use the full name, out of habit, following the Naming Framework Rules , which encourage adding an Attribute to custom attribute classes or I for interface types.

+1
source

If you look at the Philips Healthcare coding standard - C #, rule 3 @ 122, you can see that they really want the encoders to add the attribute suffix to the attributes. http://www.tiobe.com/content/paperinfo/gemrcsharpcs.pdf

Code can be generated, but the author of the code generator is probably trying to create code that matches as many standards as possible.

0
source

All Articles