枚举命名公约 - 多个 [英] Enum Naming Convention - Plural

查看:220
本文介绍了枚举命名公约 - 多个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管我在枚举和匹配属性的C#命名约定



我发现我有一个将枚举命名为复数形式的趋势,然后将其用作单数形式,例如:

  public enum EntityTypes {
Type1,Type2
}

public class SomeClass {
/ *
一些代码
* /

public EntityTypes EntityType {get;设置;}

}

当然,它的作品,这是我的风格但是,任何人都可以发现这样的惯例的潜在问题?我确实有一个丑陋命名与状态,但是:

  public enum OrderStatuses {
Pending,完成,错误,Blah,Blah
}

public class SomeClass {
/ *
某些代码
* /

public OrderStatuses OrderStatus {get; set;}

}

附加信息:
也许我的问题不够清楚。当我定义的枚举类型的变量命名时,我经常要努力。我知道最好的做法,但它并没有帮助缓解我的命名这些变量的工作。



我不可能暴露我所有的枚举属性(比如说状态)asMyStatus。



我的问题:有人会发现上述我的惯例的潜在问题吗? 这不是最佳实践。



问题重新表达:


$ b $嗯,我想我应该这样问一个问题:有人可以出一个很好的通用方式来命名枚举类型,以便在使用时,枚举实例的命名将很简单吗?

解决方案

Microsoft建议对枚举使用单数,除非枚举表示位字段(使用 FlagsAttribute )。请参阅枚举类型命名约定(Microsoft的命名指南)。



回应你的澄清,我看不出任何一个错误:

  public enum OrderStatus {Pending,Fulfilled,Error}; 

public class SomeClass {
public OrderStatus OrderStatus {get;组;
}

  public enum OrderStatus {Pending,Fulfilled,Error}; 

public class SomeClass {
public OrderStatus Status {get;组; }
}


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?

解决方案

Microsoft recommends using singular for Enums 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; }
}

or

public enum OrderStatus { Pending, Fulfilled, Error };

public class SomeClass {
    public OrderStatus Status { get; set; }
}

这篇关于枚举命名公约 - 多个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆