浏览 1722
扫码
命名规范
本文档描述了CatLib框架中的命名规范。
如果您要为为 CatLib 发起贡献,您必须遵循这份命名规范文档。
如果没有明确指定
访问级别(public|private等)则表示对所有访问级别生效。
概述
代码必须使用4个空格缩进,而不要使用制表符(tab)- 使用
using XXX,而不是new XXX.xxx() {}必须换行,且内部代码顶格书写if(true){var tf = true;}
使用
///对代码进行注释/// <summary>/// 这里对代码进行了注释/// </summary>public string VariableName = "VariableName";
对于容易
产生歧义的表达式您应该使用括号包裹if(variable1 + (++variable2) > 0){}
模板必须为TStudlyCaps(驼峰式大写)以T开头public class Bootstrap<TType>{}
接口必须为IStudlyCaps(驼峰式大写)以I开头public interface IBootstrap{}
类名及函数
类名必须为StudlyCaps(驼峰式大写)public class Bootstrap{}
函数名必须为StudlyCaps(驼峰式大写)public void MyFunc(){}
变量,常量及属性
类
公共变量名必须为StudlyCaps(驼峰式大写)public string VariableName = "hello";
类
受保护变量名必须为StudlyCaps(驼峰式大写)internal string VariableName = "hello";protected string VariableName = "hello";protected internal string VariableName = "hello";
类
私有变量名必须为camelCase(驼峰式小写)private string variableName = "hello";
类
属性名必须为StudlyCaps(驼峰式大写)public string VariableName{ get; set; }
静态变量和常量必须为StudlyCaps(驼峰式大写)public const string VariableName = "hello";public static readonly string VariableName = "hello";public static string VariableName = "hello";internal const string VariableName = "hello";protected const string VariableName = "hello";private const string VariableName = "hello";
参数必须为camelCase(驼峰式小写)public void FunctionName(Action callFunction){var localVariable = callFunction;}
枚举
枚举名必须为StudlyCaps(驼峰式大写)public enum ApplicationEvents{}
枚举元素名必须为StudlyCaps(驼峰式大写)public enum ApplicationEvents{OnStart = 1,OnInited = 2,}
命名空间
代码必须在项目名的根命名空间中namespace CatLib{}
组件
代码必须在项目名.组件名的命名空间中namespace CatLib.Routing{}
文件
文件名必须和类名一致文件必须只使用UTF-8而不使用BOM代码- 一个文件中不能出现
2个及以上的类,除非它是内部类或者类的重载