枚举的命名约定 [英] Naming Conventions for Enumerations

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

问题描述

您好


在命名枚举和变量时使用什么约定

使用枚举?


我喜欢复数/单数,例如:


公共类示例

{

public enum VehicleTypes {Car, Truck,Motorbike};

static VehicleTypes VehicleType = VehicleTypes.Car;

}


但CodeAnalysis / FXCop抱怨它:


CA1717:Microsoft.Naming:如果名称''VehicleTypes''是复数,

将其更改为单数形式

它没有抱怨


公共类示例

{

public enum VehicleType {Car,Truck,Motorbike};

static VehicleType MyVehicleType = VehicleType.Car;

}


但是我不要认为它读得不错


比尔

解决方案

>在命名枚举时使用什么约定?使用枚举的变量





这是一个开始:
http://msdn.microsoft.com/library/de...guidelines.asp


此外,请查看:
http://msdn.microsoft.com/library/de...Guidelines.asp


HTH

Erick Sgarbi
www.blog .csharpbox.com

您好吗

在命名枚举时使用什么约定和使用枚举的变量?

我喜欢复数/单数,例如:

公共类示例
{
公共枚举VehicleTypes {汽车,卡车,摩托车};
静态车辆类型车辆Type = VehicleTypes.Car;
}
但CodeAnalysis / FXCop抱怨它:

CA1717:Microsoft.Naming:如果名称''VehicleTypes''是复数,
它不会抱怨

公共类示例
{
公开enum VehicleType {Car,Truck,Motorbike};
static VehicleType MyVehicleType = VehicleType.Car;
}
但我不认为它读得很好

Bill



或******* @ yahoo.com.au 写道:

CA1717:Microsoft.Naming:如果名称''VehicleTypes''是复数,
将其更改为单数表格

它没有抱怨

公共类示例
{
public enum VehicleType {Car,Truck,摩托车};
静态VehicleType MyVehicleType = VehicleType.Car;
}


显示投诉的原因是因为复数枚举类型名称

应该与具有FlagsAttribute的枚举一起使用。

考虑这两个:


enum VehicleType {

汽车,卡车,摩托车

}


[标志]

enum JobFunctions {

看门人,老师,HeadOfSchool

}


现在在一个人的类中,你可能有:


class Person {

VehicleType vehicleType;

JobFunctions jobFunctions;

}


使用这个命名约定,您可以从

人的类型名称中看到只有一种指定的车型,但是有可能

有多种工作职能。

Oliver Sturm

-

omnibus ex nihibo ducendis sufficit unum

插入空格以防止谷歌电子邮件销毁:

MSN oliver @ sturmnet.org Jabber sturm @ ame ssage.de

ICQ 27142619 http://www.sturmnet.org / blog


感谢Erick&奥利弗


比尔


Hi There

What convention do you use when naming an enumeration and variables
that use the enumeration?

I like plural/singular, for example:

public class Example
{
public enum VehicleTypes { Car, Truck, Motorbike };
static VehicleTypes VehicleType = VehicleTypes.Car;
}

But CodeAnalysis/FXCop complains about it:

CA1717 : Microsoft.Naming : If the name ''VehicleTypes'' is plural,
change it to its singular form

It does not complain about:

public class Example
{
public enum VehicleType { Car, Truck, Motorbike };
static VehicleType MyVehicleType = VehicleType.Car;
}

But I don''t think it reads well

Bill

解决方案

> What convention do you use when naming an enumeration and variables

that use the enumeration?

Here is a start:
http://msdn.microsoft.com/library/de...guidelines.asp

Furthermore, have a look at :
http://msdn.microsoft.com/library/de...Guidelines.asp

HTH
Erick Sgarbi
www.blog.csharpbox.com
Hi There

What convention do you use when naming an enumeration and variables
that use the enumeration?

I like plural/singular, for example:

public class Example
{
public enum VehicleTypes { Car, Truck, Motorbike };
static VehicleTypes VehicleType = VehicleTypes.Car;
}
But CodeAnalysis/FXCop complains about it:

CA1717 : Microsoft.Naming : If the name ''VehicleTypes'' is plural,
change it to its singular form

It does not complain about:

public class Example
{
public enum VehicleType { Car, Truck, Motorbike };
static VehicleType MyVehicleType = VehicleType.Car;
}
But I don''t think it reads well

Bill



or*******@yahoo.com.au wrote:

CA1717 : Microsoft.Naming : If the name ''VehicleTypes'' is plural,
change it to its singular form

It does not complain about:

public class Example
{
public enum VehicleType { Car, Truck, Motorbike };
static VehicleType MyVehicleType = VehicleType.Car;
}



The reason why the complaint is shown is because plural enum type names
are supposed to be used with enums that have the FlagsAttribute.
Consider these two:

enum VehicleType {
Car, Truck, Motorbike
}

[Flags]
enum JobFunctions {
Janitor, Teacher, HeadOfSchool
}

Now in a class of a Person, you might have:

class Person {
VehicleType vehicleType;
JobFunctions jobFunctions;
}

With this naming convention you can see from the type names that the
person will have just one assigned vehicle type, but it''s possible to
have multiple job functions.
Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog


Thanks Erick & Oliver

Bill


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

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