FilterOperators 或 FilterOperatorType - C# 中枚举的正确命名格式

发布于 2024-08-02 20:15:28 字数 556 浏览 5 评论 0原文

哪种命名枚举器的合适(更易读)方式?您会考虑:

enum FilterOperators
{
    IsEqual, 
    Contains, 
    StartsWith
}

class QueryFilter
{
    FilterOperators Operator{get;set;}
}

var filter = new QueryFilter();
filter.Operator = FilterOperators.IsEqual;

可取?

enum FilterOperatorType
{
    IsEqual, 
    Contains, 
    StartsWith
}

class QueryFilter
{
    FilterOperators Operator{get;set;}
}

var filter = new QueryFilter();
filter.Operator = FilterOperatorType.IsEqual;

还是颜色ColorType

Which is the appropriate (more readable) way of naming enumerator? will you consider:

enum FilterOperators
{
    IsEqual, 
    Contains, 
    StartsWith
}

class QueryFilter
{
    FilterOperators Operator{get;set;}
}

var filter = new QueryFilter();
filter.Operator = FilterOperators.IsEqual;

Or is this preferable

enum FilterOperatorType
{
    IsEqual, 
    Contains, 
    StartsWith
}

class QueryFilter
{
    FilterOperators Operator{get;set;}
}

var filter = new QueryFilter();
filter.Operator = FilterOperatorType.IsEqual;

Also, Colors or ColorType?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

牵你的手,一向走下去 2024-08-09 20:15:28

IrritatedVowel.com 建议如下:

枚举

基于 Microsoft .NET 库标准的标准

遵循类命名约定。做
不要将“Enum”添加到末尾
枚举名称。如果枚举
表示一组按位标志,end
带复数的名称。

原因:此约定是一致的
与 .NET Framework 一起使用,并且很容易
读。

示例:

SearchOptions(按位标志)

AcceptRejectRule(普通枚举)

因此,我相信首选是 FilterOperator

IrritatedVowel.com suggests the following:

Enumerations

Standard Based Upon Microsoft .NET Library Standards

Follow class naming conventions. Do
not add "Enum" to the end of the
enumeration name. If the enumeration
represents a set of bitwise flags, end
the name with a plural.

Why: This convention is consistent
with the .NET Framework and is easy to
read.

Example:

SearchOptions (bitwise flags)

AcceptRejectRule (normal enum)

As such, I believe the preferred choice would be FilterOperator.

你穿错了嫁妆 2024-08-09 20:15:28

《框架设计指南》中说:

  • 除非它是位字段,否则请使用单数类型
  • 请对标志枚举(位字段)使用复数类型
  • 不要使用枚举后缀
  • 请勿使用标志或标志后缀
  • 不要使用前缀(例如 ADO...)

所以我的建议是过滤操作符

The "Framework Design Guideline" says:

  • Do use a singular type unless its a bit field
  • Do use plural types for flags enums (bit fields)
  • Do not use enum suffix
  • Do not use flag or flags suffixes
  • Do not use a prefix (e.g. ADO...)

So my suggestion would be FilterOperator

删除→记忆 2024-08-09 20:15:28

我认为这就是就一个标准达成一致(你可以定义自己的标准)然后坚持它。我想说,附加“类型”似乎是个好主意,尽管对于像“颜色”这样简单的东西来说,它可能看起来有点愚蠢。它确实暗示它是一个枚举,我认为这很好。

我想说最后一个例子:)

I think it's all about agreeing on a standard (you can define your own) and then sticking to it. I'd say appending "Type" seems like a good idea, even though for something as simple as "Color" it might seem a bit silly. It does hint that it is an enum, which I think is nice.

I'd say go for the last example :)

俯瞰星空 2024-08-09 20:15:28

这是非常主观的,但我首先想到的是“颜色”,它是一个包含多种颜色的列表,看起来很合适。但是,对于较小的列表,例如“FilterOperatorType”,“...Type”似乎比较合适。

简而言之,如果它们很多,那么该词的复数似乎是合适的,如果它们很少并且代表广泛的类别,那么“...类型”似乎是合适的。

This is extremely subjective, but the first thing that pops to mind is 'Colors' strikes me as a list of many colors and seems appropriate. However, for a smaller list, like 'FilterOperatorType', the '...Type' seems appropriate.

In short, if their are many the plural of the word seems appropriate, if they are few and represent broad categories the '...Type' seems appropriate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文