user6410654
user6410654

Reputation:

Naming conventions and guidelines for custom attributes

Are there any conventions (perhaps by Microsoft) on attributes if their name should be singular or plural?

I'm not sure what the naming conventations are or if there are any at all? I want an attribute for the roles in my system I'm not sure whether by convention (if any) I should pluralize it to RolesAttribute or keep it singular RoleAttribute.

- Edit -

Now I think of it custom attributes are still classes that derive from the Attribute base class, so would the conventions of classes apply to C# attributes as well?

Upvotes: 2

Views: 1052

Answers (1)

Leo
Leo

Reputation: 5142

It really depends on the functionality you are implementing. In short, if you are assigning one role using your attribute then keep it singular, if you are assigning multiple roles then make it plural.

In more general terms, Attributes should be named using clear pascal cased names and their function is to associate metadata, or declarative information with code. As with everything else in your code, make sure that they are descriptive and unambiguous.

Some good guidelines I like to follow are the following:

Upvotes: 3

Related Questions