Should Enum class file names be added to "Enum"?

When splitting classes into files, I wonder what a naming convention is for class files that contain only enumerations. Should they match the name of the enumeration, like any other class, or should they be suffixed with "Enum" so that the developer knows that the file contains only the enumeration?

For instance:

namespace MyCompanyName.MyApplication { public enum Colors { Red, Blue, Green, Yellow } } 

Could you say that the file containing the above code should have the name "Colors.cs" or "ColorsEnum.cs"? As an alternative, maybe there is another accepted naming convention for such files?

+6
source share
4 answers

Firstly, this is a complete personal / team thing.

Said:

I would call it Colors.cs . This saves the file name corresponding to the type name. When I'm working on an API, if β€œColors” is a fixed set of things represented by an enumeration, I would probably know about it, and there would be no confusion.

+5
source

The file name, in my opinion, should be the same as the name Enum, which - according to the Enum Enumeration Rules, should not have the suffix Enum. The manual also indicates that your enumeration must be singular, therefore, taking into account, it should be Color.cs

+7
source

How about creating a folder named Enums and naming the Colors.cs file?

+2
source

Creating a folder named Enumerations, Enums, or something descriptive should be enough. You can also follow the C # naming standards, which state:

"Enum names Do not use a prefix for enum value names. For example, do not use a prefix such as a declaration for ADO enumerations, or rtf for extended text enumerations, etc.

It also means that you should not include the name of an enumeration type in the names of enumeration values. The following code example demonstrates the misappropriation of enumeration values.

C # code as follows

 public enum Teams { TeamsAlpha, TeamsBeta, TeamsDelta } 

References: Names of classes, structures, and interfaces

+1
source

Source: https://habr.com/ru/post/891063/


All Articles