• Framework Design GuidelinesNaming 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
    identifier Casing Example
    Namespace Pascal System.Security
    Type Pascal StreamReader
    Interface Pascal IEnumerable
    Method Pascal Object
    Property Pascal int Length{get;set;}
    Event Pascal public event EventHandler
    Field Pascal public const Min = 0
    Enum value Pascal public enum FileMode
    Parameter camel public class Convert(string str,int num)

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

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

         DO NOT:

    Pascal Camel Not
    BitFlag bitFlag Bitflag
    Callback callback CallBack
    FileName fileName Filename
    Id id ID
    LogOn logOn LogIn

    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.

    BaseType Derived/Implementing Type Guideline
    System.Attribute Do add the suffix "Attribute" to names of custom attributes classes.
    System.Delegate Do : add EventHandler and Callback. Do not : used Delegate
    System.EventArgs Do: add EventArgs
    System.Enum   Do not: used keyword and add suffix Enum or Flag
    System.Exception Do add the suffix Exception.
    IDictionary<Tkey,TValue> Do used the suffix Dictionary
    IEnumerable;IList;ICollection Do add the suffix Collection
    System.IO.Stream   Do use Stream
    CodeAccessPermission Do 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.

  • 相关阅读:
    【杂文】搞一个对拍程序
    【学习笔记】线段树详解(全)
    【杂文】5亿大质数表(5e8)
    【学习笔记】OI玄学道—代码坑点
    【题解】动态逆序对 [CQOI2011] [P3157] [BZOJ3295] [P1393]
    【题解】永无乡 [HNOI2012] [BZOJ2733] [P3224]
    【题解】晋升者计数 Promotion Counting [USACO 17 JAN] [P3605]
    【题解】古代猪文 [SDOI2010] [BZOJ1951] [P2480]
    【题解】PERIOD
    Navicat Premium 12连接ubuntu18 ,Mysql 5.7.27-0
  • 原文地址:https://www.cnblogs.com/cuiyansong/p/NamingGuidelines.html
Copyright © 2020-2023  润新知