IDesign C#编程规范(之四)

编程|规范

续之三,本文是IDesign C#编程规范的第三章。

3 项目设置和项目结构
Project Settings and Project Structure

1. 总是以4级警告建立项目(图略)。
Always build your project with warning level 4
2. 在发布版中将警告作为错误(注意这不是VS.NET的缺省设置)(图略)。
Treat warning as errors in Release build (note that this is not the default of VS.NET).
a) 虽然是可选的,本标准也推荐在调试版中将警告作为错误。
Although it is optional, this standard recommend treating warnings as errors in debug builds as well.
3. 永远不要抑制特定的编译警告(图略)。
Never suppress specific compiler warnings.
4. 总是在应用程序的配置文件中显式地说明支持的运行时版本。参见Programming .NET Components第五章。
Always explicitly state your supported runtime versions in the application configuration file. See Chapter 5 in Programming .NET Components.
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v2.0.0.0"/>
<supportedRuntime version="v1.1.5000.0"/>
</startup>
</configuration>
5. 避免显式地自定义版本改向和绑定到CLR程序集。
Avoid explicit custom version redirection and binding to CLR assemblies.
6. 避免显式的预编译定义(#define)。使用项目设置定义条件编译常量。
Avoid explicit preprocessor definitions (#define). Use the project settings for defining conditional compilation constants.
7. 不要在AssemblyInfo.cs中放任何逻辑。
Do not put any logic inside AssemblyInfo.cs.
8. 除了在AssemblyInfo.cs,不要在任何文件中放程序集属性。
Do not put any assembly attributes in any file besides AssemblyInfo.cs.
9. 在AssemblyInfo.cs中提供所有字段,例如公司名称、描述、版权等。
Populate all fields in AssemblyInfo.cs such as company name, description, copyright notice.
10. 所有程序集应该使用相对路径引用。
All assembly references should use relative path.
11. 不允许在程序集中循环引用。
Disallow cyclic references between assemblies.
12. 避免多模块的程序集。
Avoid multi-module assemblies.
13. 缺省总是以非检查的方式运行(为了性能考虑),但是对易于溢出或下溢的操作显式使用检查模式(图略)。
Always run code unchecked by default (for performance sake), but explicitly in checked mode for overflow or underflow prone operations.
int CalcPower(int number,int power)
{
int result = 1;
for(int count = 1;count <= power;count++)
{
checked
{
result *= number;
}
}
return result;
}
14. 避免使用Exception窗口(Debug|Exceptions)篡改异常处理。
Avoid tampering with exception handling using the Exception window (Debug|Exceptions).
15. 努力对同一逻辑应用程序中(通常是一个解决方案)的所有程序集和客户端使用统一的版本号。
Strive to use uniform version numbers on all assemblies and clients in the same logical application (typically a solution).
16. Visual Studio.NET应用的配置文件命名为App.config,并将其包括在项目中。
Name your Visual Studio.NET application configuration file as App.config, and include it in the project.
17. 避免使用显式代码来排除方法(#if#endif),而是使用条件方法。
Avoid explicit code exclusion of method calls (#if...#endif). Use conditional methods instead.
public class MyClass
{
[Conditional("MySpecialCondition")]
public void MyMethod()
{}
}
18. 将VS.NET缺省的项目结构改为标准的布局,对项目文件夹和文件应用统一的结构。
Modify VS.NET default project structure to your project standard layout, and apply uniform structure for project folders and files.
19. 链接一个包含所有解决方案级信息的全局共享文件(图略)。
Link all solution-wide information to a global shared file:
20. 制表符选用"插入空格",使用3个空格代替制表符。
Insert spaces for tabs. Use 3 spaces instead of tabs。
a) 在工具|选项|文本编辑器|C#|制表符中设置
Tools|Options|Text Editor|C#|Tabs
21. 发布版中应该包含调试符号。
Release build should contain debug symbols.
22. 总是对程序集签名,包括客户端应用程序。
Always sign your assemblies, including the client applications.
23. 总是使用项目的SNK文件对互操作程序集签名(图略)。
Always sign interop assemblies with the project's SNK file

(待续)

时间: 2024-08-03 00:56:02

IDesign C#编程规范(之四)的相关文章

IDesign C#编程规范(一)

编程|规范 IDesign发布了C#编程规范,小鸡射手从Only4Gurus下载浏览后决心抽时间翻译一下,以更好地学习. 目录内容如下: 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.NE

IDesign C#编程规范(二)

编程|规范 续之一,小鸡射手接着翻译了IDesign编码规范的第二章前部. 2 编码惯例 Coding Practices 1. 避免在一个文件中放多个类. Avoid putting multiple classes in a single file. 2. 一个文件应该只对一个命名空间提供类型.避免在同一文件中有多个命名空间. A single file should only contribute types to a single namespace. Avoid having mult

实现高效Java编程规范的十一条基础规则

编程|规范 本文介绍的Java规则的说明分为5个级别,级别1是最基本也是最重要的级别,在今后将陆续写出其他的规则.遵守了这些规则可以提高程序的效率.使代码有更好的可读性等. (1) 避免使用NEW关键字来创建String对象 把一个String常量copy到String 对象中通常是多余.浪费时间的. Public class test{ Public void method(){ System.out.print (str); } private String str = new String

JAVA 编程规范

编程|规范 1. 应用范围 本规范应用于采用J2EE规范的项目中,所有项目中的JAVA代码(含JSP,SERVLET,JAVABEAN,EJB)均应遵守这个规范.同时,也可作为其它项目的参考. 2. 设计类和方法 2.1 创建具有很强内聚力的类 方法的重要性往往比类的重要性更容易理解,方法是指执行一个统一函数的一段代码.类常被错误的视为是一个仅仅用于存放方法的容器.有些开发人员甚至把这种思路作了进一步的发挥,将他们的所有方法放入单个类之中. 之所以不能正确的认识类的功能,原因之一是类的实现实际上

C#编程规范和惯例

编程|规范 谁都会写代码!几个月的编程经验可以让你写出"可运行应用程序".让它可运行容易,但是以最有效率的方式编码就需要下更多的功夫! 要知道,大多数程序员在写"可运行代码,"而不是"高效代码".我们在这个指南课程前面提到,你想成为你们公司"最尊贵的专业人员"吗?写"高效代码"是一项艺术,你必须学习和实践它. 命名惯例和规范 注记 : Pascal 大小写形式-所有单词第一个字母大写,其他字母小写.Came

C# 编程规范

编程|规范 C# 编码规则 一.命名 1.用pascal规则来命名方法和类型. public class TextBox { public void DataBind() { } } 2.用camel规则来命名局部变量和方法的参数. string userName; public AddUser(string userId, byte[] password); 3.所有的成员变量前加前缀 _ public class Database { private string _connectionSt

Visual Basic编程规范

visual|编程|规范 Visual Basic编程规范 1.      Visual Basic IDE(集成开发环境)设置        必须打开设置选项的"要求变量声明","对齐控件到网格","自动缩进"开关.        Tab的宽度统一为4个空格,网格单位一律设为:width 60 height 60. 2.     命名约定        (注意:在任何时候,不能使用中文及全角字符,只允许使用英文字母.下划线和数字) 2.1   

IDesign C#编码规范(之三)

编码|规范 续之二,IDesign C#编码规范之三. 34. 避免使用new继承修饰符,而是使用override. Avoid using the new inheritance qualifier. Use override instead. 35. 对非密封类总是将public和protected方法标记为virtual. Always mark public and protected methods as virtual in a non sealed class. 36. 除非涉及到

PB编程规范

作者:达通兴电脑科技公司(www.study01job.com) 郭宝利 一.PB编程规范综述 二.PB对象命名规范 三.PB变量命名 四.PB程序规范 五.PB控件编程规范 六.PB的用户反馈 七.提高PB程序的健壮性 八.PB的文档标准 九.PB的错误处理