当前位置:首页 > Windows程序 > 正文

转载 C#中敏捷开发规范

2021-03-19 Windows程序

转载原地址 

1.命名规则和风格 Naming Conventions and Style
2  编码惯例 Coding Practices
3  项目设置和结构 Project Settings and Structure
4  Framework特别指导 Framework Specific Guidelines
 4.1  数据访问 Data Access
 4.2  ASP.NET和Web Service ASP.NET and Web Services
 4.3  序列化 Serialization
 4.4  多线程 Multithreading
 4.5  Remoting Remoting
 4.6  安全 Security
 4.7  服务组件 Enterprise Services
5  资源 Resources


命名规则和风格 
Naming Conventions and Style

1.  类和方法名采用Pascal风格 
    Use Pascal casing for type and method names 
    public class SomeClass 
    { 
       public SomeMethod(){} 
    } 
2.  局部变量和方法参数采用camel风格 
    Use camel casing for local variable names and method arguments 
    int number; 
    void MyMethod(int someNumber) 
    {} 
3.  接口名采用I作为前缀 
    Prefix interface name with I  
    interface IMyInterface 
    {..} 
4.  私有成员变量采用m_作为前缀
    Prefix private member variables with m_ 
    public class SomeClass 
    { 
       private int m_Number; 
    } 
5.  自定义属性类名采用Attribute作为后缀
    Suffix custom attribute classes with Attribute.  
6.  自定义异常类名采用Exception作为后缀 
    Suffix custom exception classes with Exception. 
7.  采用动词-对象对命名方法,例如ShowDialog() 
    Name methods using verb-object pair, such as ShowDialog() 
8.  有返回值的方法应该取名表示其返回值,例如GetObjectState()
    Methods with return values should have a name describing the value returned, such as GetObjectState(). 
9.  采用描述性的变量名。 
    Use descriptive variable names. 
    a) 避免采用单字母的变量名,如i或t;而是采用index或temp。
       Avoid  single character variable names, such as i or  t. Use  index or temp instead.  
    b) 对public和protected成员避免采用用匈牙利命名法。
       Avoid using Hungarian notation for public or protected members.  
    c) 不要采用缩写(例如将number缩写为num)。
       Do not abbreviate words (such as num instead of number). 
10.  总是使用C#预定义的类型,而不是使用System命名空间中的别名。例如:采用object不用Object,采用string不用String,采用int不用Int32。
     Always use C# predefined types rather than the aliases in the  System namespace. 
     For example:  
     object NOT Object 
     string NOT String 
     int    NOT Int32 
11.  对于泛型,类型采用大写字母。当处理.NET类型Type时保留后缀Type。
     With generics,  use capital letters for types. Reserve suffixing Type when dealing with the .NET type Type. 
     // 正确:
     //Correct: 
     public class LinkedList 
     // 避免使用:
     //Avoid:  
     public class LinkedList  
12.  采用有意义的命名空间名,例如产品名称或公司名称。
     Use meaningful namespaces such as the product name or the company name. 
13.  避免使用类的全称,而是采用using语句。
     Avoid fully qualified type names. Use the using statement instead.  
14.  避免在命名空间内使用using语句。
     Avoid putting a using statement inside a namespace. 
15.  将所有framework命名空间名放在一起,后面放自定义或第三方的命名空间名。
     Group all framework namespaces together and put custom or third party namespaces underneath. 
     using System; 
     using System.Collections; 
     using System.ComponentModel; 
     using System.Data; 
     using MyCompany; 
     using MyControls; 
16.  采用委托推断,不要显式实例化委托。
     Use delegate inference instead of explicit delegate instantiation  
     delegate void SomeDelegate(); 
     public void SomeMethod() 
     {}
     SomeDelegate someDelegate = SomeMethod; 
17.  严格遵守缩进格式。
     Maintain strict indentation. 
     a) 缩进采用3个空格。 
        Use 3 spaces for indentation. 
     b) 不用采用tab或非标准的缩进,如1、2或4个空格。
        Do not use tabs or non-standard indentation like 1, 2 or 4 spaces.  
18.  注释缩进和其注释的代码在同一层次。
       Indent comment at the same level of indentation as the code you are documenting. 
19.  所有注释要经过拼写检查。拼写错误的注释表明开发的草率。
      All comments should pass spell checking. Misspelled comments indicate sloppy development.  
20.  所有成员变量应该定义在前面,和属性或方法间空开一行。
      All member variables should be declared at the top, with one line separating them from the properties or methods.  
     public class MyClass 
     { 
        int m_Number; 
        string m_Name;

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/63643.html