I'm asking this question despite having read similar but not exactly what I want at C# naming convention for enum and matching property
I found I have a tendency to name enums in plural and then 'use' them as singular, example:
public enum EntityTypes {
Type1, Type2
}
public class SomeClass {
/*
some codes
*/
public EntityTypes EntityType {get; set;}
}
Of course it works and this is my style, but can anyone find potential problem with such convention? I do have an "ugly" naming with the word "Status" though:
public enum OrderStatuses {
Pending, Fulfilled, Error, Blah, Blah
}
public class SomeClass {
/*
some codes
*/
public OrderStatuses OrderStatus {get; set;}
}
Additional Info: Maybe my question wasn't clear enough. I often have to think hard when naming the variables of the my defined enum types. I know the best practice, but it doesn't help to ease my job of naming those variables.
I can't possibly expose all my enum properties (say "Status") as "MyStatus".
My question: Can anyone find potential problem with my convention described above? It is NOT about best practice.
Question rephrase:
Well, I guess I should ask the question this way: Can someone come out a good generic way of naming the enum type such that when used, the naming of the enum 'instance' will be pretty straightforward?
Coming in a bit late...
There's an important difference between your question and the one you mention (which I asked ;-):
You put the enum definition out of the class, which allows you to have the same name for the enum and the property:
In this case, I'd follow the MS guidelins and use a singular name for the enum (plural for flags). It's probaby the easiest solution.
My problem (in the other question) is when the enum is defined in the scope of the class, preventing the use of a property named exactly after the enum.
Microsoft recommends using singular for
Enum
s unless theEnum
represents bit fields (use theFlagsAttribute
as well). See Enumeration Type Naming Conventions (a subset of Microsoft's Naming Guidelines).To respond to your clarification, I see nothing wrong with either of the following:
or
Best Practice - use singular. You have a list of items that make up an Enum. Using an item in the list sounds strange when you say
Versions.1_0
. It makes more sense to sayVersion.1_0
since there is only one 1_0 Version.If you are trying to write straightforward, yet forbidden code like this:
Your options are:
Ignore the MS recommendation and use a prefix or suffix on the enum name:
Move the enum definition outside the class, preferably into another class. Here is an easy solution to the above:
The situation never really applies to plural.
An
enum
shows an attribute of something or another. I'll give an example:You can have one type, but try think of it in the multiple, rather than plural:
Humour.Irony | Humour.Sarcasm
Rather than
Humours { Irony, Sarcasm }
You have a sense of humour, you don't have a sense of humours.
I started out naming enums in the plural but have since changed to singular. Just seems to make more sense in the context of where they're used.
Compare to:
I find the singular form to sound more natural in context. We are in agreement that when declaring the enum, which happens in one place, we're thinking "this is a group of whatevers", but when using it, presumably in many places, that we're thinking "this is one whatever".