Framework Design Guidelines---Naming Guidelines(C# 命名规则)

第三章:名称规范

风格:PascalCasing 与 camelCasing

1. DO : PascalCasing used for namespace ,type,member names consisting of multiple words.

           camelCasing used for parameter names.

examples:

           

Naming Guideline
identifierCasingExample
NamespacePascalSystem.Security
TypePascalStreamReader
InterfacePascalIEnumerable
MethodPascalObject
PropertyPascalint Length{get;set;}
EventPascalpublic event EventHandler
FieldPascalpublic const Min = 0
Enum valuePascalpublic enum FileMode
Parametercamelpublic class Convert(string str,int num)

 

 

 

 

 

 

 

 

 

2. DO : 专有名词缩写 ,如 IO。

            当专有名词三个或四个单词缩写时,应只大写首字母其余小写,如Html ,Xml。

     DO NOT:

PascalCamelNot
BitFlagbitFlagBitflag
CallbackcallbackCallBack
FileNamefileNameFilename
IdidID
LogOnlogOnLogIn

 

 

 

 

 

 

3.有意的命名:GetWindows比GetWin好。

4.not confict with keywords

5.use semantically interstring names rather than language-specific keywords for type names. For example: GetLength > GetInt

6.Use a generic CLR type name : ToInt64 > ToLong

7.If has no semanticlly names ,use a common name: value , item

8.use a name similar to the old API when creating new versions of an existing API. Like: AppDomain,AppDomainCreat.

9.If name has only a name to make sense, use a numeric suffix to indicate a version of an existing name.Like: X509Certificate2

10.Not use "Ex" as the suffix, use Car2,not CarEx.

11.use 64 when introducing versions of APIs that operate on a 64-bit integer instead of 32-bit integer.

12.DLL named:

    1) <Company>.<Component>.dll  : Microsoft.VisualBasic.dll

    2) <Company>.(<Product>|<Technology>)[.<Feature>][.<Subnamespace>]   : Microsoft.Visualstudio.Design

    3) use Pascal Casing and Separate namespace component with periods. Like: Mircosoft.Office.PowerPoint.

13.Do not introduce generic type names such as Element , Event ,Log .use FormElement, XmlNode,EventLog

14.Do not give types that would conflict with any type in the Core namespaces.

15.Names of Classes,Structs,Interfaces

    1) Do name classes and structs with nouns or noun phrases,using PascalCasing.

    2) Do name interfaces with adjective phrases, or occasionally with nouns or noun phrases.

    3) Do prefix interface names with the letter "I" ,to indicate that types in an interface.

    4) Do name generic type parameters with descriptive names unless a single-letter name is completely self-explanatory and a descriptive name would not add value.

    5) Do prefix descriptive type parameter names with T

    6) Name rules for types dervied from or implementing certain core type.

 

BaseTypeDerived/Implementing Type Guideline
System.AttributeDo add the suffix "Attribute" to names of custom attributes classes.
System.DelegateDo : add EventHandler and Callback. Do not : used Delegate
System.EventArgsDo: add EventArgs
System.Enum  Do not: used keyword and add suffix Enum or Flag
System.ExceptionDo add the suffix Exception.
IDictionary<Tkey,TValue>Do used the suffix Dictionary
IEnumerable;IList;ICollectionDo add the suffix Collection
System.IO.Stream  Do use Stream
CodeAccessPermissionDo add the suffix Permission

 16.Naming Enumerations

      1) Do use a singular type name for an enumeration unless its values are bit fields.

      2) Do use a plural type name for an enumeration with bit fields as values, also called flags enum.

  3) Do not use an Enum , Flag ,Flags . 

17.Names of Method: use verb or verb phrases

18.Names of Properties: use noun phrase or adjective names

  1) Do not :have properties that match the name of Get methods .

  2) Do name collection properties with a plural phrase describing the items in the collection instead of using a singular phrase followed by List or Collection.

  3) Do name Boolean properties with an affirmative phrase: CanRead IsFinished Has....

19.Names of Event: named with verb, and verb tense .

  1) Do Like Clicked , DroppedDown

  2) Do give events names with a concept of before or after: Closing Closed.

  3) Do not use Before or After

  4) Do use two parameters named  sender and e in event handler

  5) Do name event argument classed with the EventArgs suffix.

20.Names of Fields

  1) Do use PascalCasing in field names

  2) Do name fields using a noun,noun phrase or adjective

  3) Do not use a prefix for field names, Like Private field use "_Collection"

21.Names of Parameters

  1) Do use camelCasing in parameter names.

  2) Do use descriptive parameter names .

22.Naming Operator Overload parameters

  1) Do use left and right for binary operator overload parameter names if there is no meaning to the parameters.

  2) Do use value for unary operator overload parameter names if there is no meaning to the parameters.

  3) Do not use abbreviations or numeric indices for operator overload parameter names.

23.Naming Resources

  1) Do use PascalCasing in resource keys.

  2) Do provide descriptive rather than short identifiers. Keep them concise where possible ,but do not sacrifice readability for space

  3) Do not use keyword

  4) Do use only alphanumeric characters and underscores in naming resouces.

  5) Do use a identifier suffix for Exception:Like , ArgumentExceptionIllegalcharacters, ArgumentExecptionInvalidateName.

 

Over.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/cuiyansong/archive/2013/04/27/NamingGuidelines.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值