我要问这个问题,尽管在看过类似的,但不是我想要的http://stackoverflow.com/questions/495051/c-naming-convention-for-enum-and-matching-property
I'm asking this question despite having read similar but not exactly what I want at http://stackoverflow.com/questions/495051/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.
我不可能暴露我的所有枚举的属性(比如状态)作为MyStatus。
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.
问另一种方式:
嗯,我想我应该问的问题是这样的:?有人能站出来命名枚举类型的好通用的方式,这样使用时,枚举实例的命名将是pretty的直白
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?
Microsoft建议使用单数为枚举
取值,除非枚举
重presents位字段(使用FlagsAttribute为好)。请参阅微软的命名准则)。
Microsoft recommends using singular for Enum
s unless the Enum
represents bit fields (use the FlagsAttribute
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:
public enum OrderStatus { Pending, Fulfilled, Error };
public class SomeClass {
public OrderStatus OrderStatus { get; set; }
}
或
public enum OrderStatus { Pending, Fulfilled, Error };
public class SomeClass {
public OrderStatus Status { get; set; }
}