All Projects → hiram3512 → CSharpNamingGuidelines

hiram3512 / CSharpNamingGuidelines

Licence: other
C#命名规范中文版/C#编码规范中文版

Projects that are alternatives of or similar to CSharpNamingGuidelines

Naming Cheatsheet
Comprehensive language-agnostic guidelines on variables naming. Home of the A/HC/LC pattern.
Stars: ✭ 9,475 (+31483.33%)
Mutual labels:  naming-conventions, guidelines, naming-schemes
discussion
記錄有關繁化姬的議題或是內容
Stars: ✭ 33 (+10%)
Mutual labels:  chinese, chinese-translation
Kivy Cn
A Chinese Translation of Kivy Programming Guide Based on Kivy 1.9.2 中文翻译Kivy开发文档
Stars: ✭ 219 (+630%)
Mutual labels:  chinese, chinese-translation
PHP-Chinese
PHP Chinese Conversion (中文繁簡轉換)
Stars: ✭ 37 (+23.33%)
Mutual labels:  chinese, chinese-translation
Awesome Macos Command Line Zh
用你的 macOS 终端搞事情。(Use your macOS terminal shell to do awesome things. )
Stars: ✭ 117 (+290%)
Mutual labels:  chinese, chinese-translation
Icopy Site.github.io
icopy.site github mirror
Stars: ✭ 142 (+373.33%)
Mutual labels:  chinese, chinese-translation
ark-pixel-font
Open source Pan-CJK pixel font / 开源的泛中日韩像素字体
Stars: ✭ 1,767 (+5790%)
Mutual labels:  chinese, chinese-translation
alfred-chinese-converter
支持 OpenCC 簡繁體中文詞彙級別轉換、異體字轉換以及地區習慣用詞轉換的 Alfred 2 workflow
Stars: ✭ 42 (+40%)
Mutual labels:  chinese, chinese-translation
china-topdeveloper
Google Play中国顶尖开发者名单,后续更新
Stars: ✭ 22 (-26.67%)
Mutual labels:  china, chinese
Database-Naming-Convention
Database Naming Conventions & Best Practices
Stars: ✭ 76 (+153.33%)
Mutual labels:  naming-conventions, naming-convention
Alfred Parrot
📝 一款可以多种语言翻译的 Alfred Workflow
Stars: ✭ 89 (+196.67%)
Mutual labels:  chinese, chinese-translation
CategoryTool
Unity Editor tool to create Categories in the Hierarchy. The Categories work as dividers between GameObjects.
Stars: ✭ 47 (+56.67%)
Mutual labels:  csharp-code, csharp-script
Awesome Cn
awesome项目中文翻译,提升查阅效率
Stars: ✭ 62 (+106.67%)
Mutual labels:  chinese, chinese-translation
Swiftui Tutorials
A code example and translation project of SwiftUI. / 一个 SwiftUI 的示例、翻译的教程项目。
Stars: ✭ 1,992 (+6540%)
Mutual labels:  chinese, chinese-translation
Springboot
Spring Boot chinese document. Spring Boot 2.1.5 中文文档
Stars: ✭ 703 (+2243.33%)
Mutual labels:  chinese, chinese-translation
Translatorx
JetBrains 系列软件汉化包 关键字: Android Studio 3.5 汉化包 CLion 2019.3 汉化包 DataGrip 2019.3 汉化包 GoLand 2019.3 汉化包 IntelliJ IDEA 2019.3 汉化包 PhpStorm 2019.3 汉化包 PyCharm 2019.3 汉化包 Rider 2019.3 汉化包 RubyMine 2019.3 汉化包 WebStorm 2019.3 汉化包
Stars: ✭ 4,856 (+16086.67%)
Mutual labels:  chinese, chinese-translation
Jetbrains In Chinese
JetBrains 系列软件汉化包 关键字: Android Studio 3.5 汉化包 CLion 2019.3 汉化包 DataGrip 2019.3 汉化包 GoLand 2019.3 汉化包 IntelliJ IDEA 2019.3 汉化包 PhpStorm 2019.3 汉化包 PyCharm 2019.3 汉化包 Rider 2019.3 汉化包 RubyMine 2019.3 汉化包 WebStorm 2019.3 汉化包
Stars: ✭ 3,912 (+12940%)
Mutual labels:  chinese, chinese-translation
Microservices
Microservices from Design to Deployment 中文版 《微服务:从设计到部署》
Stars: ✭ 4,637 (+15356.67%)
Mutual labels:  chinese, chinese-translation
awesome-malware-analysis
Defund the Police.
Stars: ✭ 9,181 (+30503.33%)
Mutual labels:  chinese, chinese-translation
Lightning network resources zh
💡 閃電網路資源整理
Stars: ✭ 37 (+23.33%)
Mutual labels:  chinese, chinese-translation

C#命名规范中文版/C#编码规范中文版

示例

/*******************************************************************
 * Description:This is a example class
 * Version: 1.0.0
 * Date: 20180218
 * Author: Hiram  
 * Email: [email protected]    
 * Copyright @ www.wikipedia.org
 *******************************************************************/

using System;

/// <summary>
/// 命名空间(Pascal)
/// </summary>
namespace Namespace
{
    /// <summary>
    /// 类(Pascal)
    /// </summary>
    public class Class
    {
        /// <summary>
        /// 属性(Pascal)
        /// </summary>
        public int Property { get; set; }

        /// <summary>
        /// 委托(Pascal):EventHandler后缀
        /// </summary>
        public delegate void EvnetHandler();

        /// <summary>
        /// 事件(Pascal):On前缀
        /// </summary>
        public event EvnetHandler OnEvent;

        /// <summary>
        /// 公有字段(Pascal)
        /// </summary>
        public readonly int Field1;

        /// <summary>
        /// 受保护字段(Pascal)
        /// </summary>
        protected int Field2;

        /// <summary>
        /// 私有字段(_Camel)
        /// </summary>
        private int _field3;
        
        /// <summary>
        /// 方法(Pascal)
        /// </summary>
        /// <param name="args">参数(Camel)</param>
        public void Method(int args)
        {
            //局部变量(Camel)
            int variable = 10;
        }
    }

    /// <summary>
    /// 接口(Pascal)
    /// </summary>
    public interface IInterface
    {
        /// <summary>
        /// 属性接口(Pascal)
        /// </summary>
        int Property { get; set; }

        /// <summary>
        /// 方法接口(Pascal)
        /// </summary>
        /// <param name="args"></param>
        void Method(int args);
    }

    /// <summary>
    /// 枚举(Pascal)
    /// </summary>
    enum Enum
    {
        Enum1,//枚举值(Pascal)
        Enum2,//枚举值(Pascal)
    }
}

参考资料


通用规则

所有的命名都是以下面两种方式进行命名:

  • PascalCasing(匈牙利命名法:每个词的第一个字母大写)
  • camelCasing(骆驼命名法:第一个词的第一个字母小写,之后每个词的第一个字母大写)
类型 命名方式 示例
Namespace Pascal namespace System.Security { ... }
Type Pascal public class StreamReader { ... }
Interface Pascal public interface IEnumerable { ... }
Method Pascal public virtual string ToString();
Property Pascal public int Length { get; }
Delegate Pascal public delegate void EvnetHandler();
Event Pascal public event EventHandler Exited;
Public Field Pascal public readonly int Min = 0;
Protected Field Pascal protected int Min = 0;
private Field Camel private int _min = 0;
Enum Pascal public enum FileMode
Parameter Camel public static int ToInt32(string value)
Local Variable Camel void Method(){int number = 10;}

特殊说明

注释

文件注释: 文件注释以如下方式进行,在扩展注释时(回车换行时)会自动添加注释行.

/*******************************************************************
* Description:This is a example class
* Version: 1.0.0
* Date: 20180218 
* Author: Hiram  
* Email: [email protected]    
* Copyright @ www.wikipedia.org
*******************************************************************/

命名空间 类型 接口 方法名 属性 事件 字段 枚举:以"///"的方式注释,编辑器会自动完善注释,并且可以用生成工具直接生成代码注释文档.

      /// <summary>
      /// 方法(Pascal)
      /// </summary>
      /// <param name="args">参数(Camel)</param>
      public void Method(int args)
      {
          //局部变量(Camel)
          int variable = 10;
      }

其他注释:以"//"的方式注释在上一行或行尾添加注释(比如局部变量,逻辑行) 段落注释:以如下方式进行

/*
       public void Method()
       {

       }
*/

待办及高亮:在注释中添加"ToDo"高亮显示注释

命名空间

类型

  • 结构体命名方式与类一致
  • 泛型默认T
  • 多个泛型根据反编译微软dll,建议命名T1,T2,T3,T4...

接口

接口定义以"I"开头,比如IInterface,IPlayer

方法

属性

属性都以Pascal方式命名

委托

微软官方建议添加以下两种后缀

  • EventHandler
  • Callback 微软官方不建议添加以下后缀
  • Delegate

事件

  • 微软官方建议:事件参数添加后缀"EventArgs"
  • 习惯命名:事件以On为前缀(比如OnClick)

字段

微软团队初期使用Camel方式命名私有字段,后来逐步采用下划线+Camel方式命名,这样做的好处是不必再识别字段是否是局部变量.

字段建议是非Public类型的,以属性替换公有的字段:这样外部访问更安全(readonly,const等除外),并且外部调用者全部使用Pascal命名方式调用对象逻辑.

微软官方只规定了public/protected以Pascal方式命名,对internal,private类型的字段没有说明,因此各种第三方规范和插件中对私有字段规范也不一致.

针对官方的示例代码,书写习惯,智能提示,代码补全和约定俗成的C#规范,建议private采用下划线+Camel方式命名,非Private字段采用Pascal方式命名.

参考微软官方命名规则,C#高级编程,Resharp命名规范,.Net源码命名规则,建议字段命名方式如下:

  • public/protected/internal以Pascal方式命名
  • private以下划线+Camel方式命名
       public readonly int Field1;
       public const int Field2 = 0;

       internal readonly int Field3;
       internal const int Field4 = 0;

       private int _field5;
       private static int _field6;
       private readonly int _field7;
       private const int _field8 = 0;
  • 以m_为前缀的方式不建议(C++命名方式)
  • 以类型为前缀的方式不建议(比如bool类型的字段以b为前缀,枚举以e为前缀)
  • 以类型为后缀的方式不建议(比如单位列表unitList,直接取名为units)

枚举

参数

局部变量

局部变量可以使用var自动声明类型

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].