我问这个问题,尽管读过类似的,但不完全是我想在c#命名约定enum和匹配属性
我发现我倾向于用复数来命名枚举,然后用单数来“使用”它们,例如:
public enum EntityTypes {
Type1, Type2
}
public class SomeClass {
/*
some codes
*/
public EntityTypes EntityType {get; set;}
}
当然,这是我的风格,但谁能发现这种惯例的潜在问题?不过,我对“地位”这个词确实有一个“丑陋”的命名:
public enum OrderStatuses {
Pending, Fulfilled, Error, Blah, Blah
}
public class SomeClass {
/*
some codes
*/
public OrderStatuses OrderStatus {get; set;}
}
额外的信息:
也许我的问题还不够清楚。在为我所定义的枚举类型的变量命名时,我经常需要认真思考。我知道最佳实践,但这无助于减轻我命名这些变量的工作。
我不能暴露我所有的枚举属性(说“状态”)为“MyStatus”。
我的问题:有人能发现上面描述的约定的潜在问题吗?这与最佳实践无关。
问题改述:
好吧,我想我应该这样问这个问题:有人能想出一个很好的通用方式命名枚举类型,这样在使用时,命名枚举“实例”将非常直接?
The reason for using a plural for a enum declaration is the fact that ( at the time of declaration ) we declare it with multiple values, so plural seems good...
But we ignore the fact that enum when declared specifies what value it can have ( from the given set of values ). It doesn't mean that the instance of that enum will store multiple values.....
When we write:
enum Days { MON, TUE, WED, THU, FRI, SAT, SUN};
We are making it plural because of the multiple values provide..
However when used (Days day = Days.MON; ) we completely ignore that instance of that enum is supposed to have a single value....
So when we write :
enum Day { MON, TUE, WED, THU, FRI, SAT, SUN };
We mean that there is a enum that can have any one day as its value, so singular is more appropriate.
Although (already described above ), to get around this without using singular names is by using any kind of Indicator, like DayEnum or EDay ( i prefer the second one)....