FxCop设计规则

上传人:飞*** 文档编号:53054138 上传时间:2018-08-27 格式:PDF 页数:11 大小:15.05KB
返回 下载 相关 举报
FxCop设计规则_第1页
第1页 / 共11页
FxCop设计规则_第2页
第2页 / 共11页
FxCop设计规则_第3页
第3页 / 共11页
FxCop设计规则_第4页
第4页 / 共11页
FxCop设计规则_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《FxCop设计规则》由会员分享,可在线阅读,更多相关《FxCop设计规则(11页珍藏版)》请在金锄头文库上搜索。

1、FxCop 设计规则一、Design(设计)1. Abstract types should not have constructors 抽象类不应该声明构造方法2. Assemblies should have valid strong names 程序集应该具有强名称3. Avoid empty interfaces 避免使用空的接口4. Avoid excessive parameters on generic types 避免在泛型类中使用过多的类型参数5. Avoid namespaces with few types 避免让名字空间含有过少的类型6. Avoid out param

2、eters 避免使用out 类型的参数7. Collections should implement generic interface 集合类应该实现泛型接口8. Consider passing base types as parameters 尽量使用基本类型作为参数9. Declare event handlers correctly 正确的声明事件处理器,事件处理器不应该具有返回值10. Declare types in namespaces 应该在名字空间里面定义类型,而不是外面11. Default parameters should not be used 不应该使用参数默认值

3、(C#没有参数默认值)12. Define accessors for attribute arguments 应该为特性 (特性) 的构造方法参数定义访问器,其名字跟构造方法参数仅首字母大小写不一样13. Do not catch general exception types 不要捕捉普通的异常(即System.Exception)14. Do not declare protected members in sealed types 不要在封闭类型中定义受保护的成员15. Do not declare static members on generic types 不要在泛型类型中使用静

4、态成员16. Do not declare virtual members in sealed types 不要在封闭类型中定义虚成员17. Do not declare visible instance fields 不要定义可见的(public/internal )实例域变量18. Do not expose generic lists 不要直接暴露范型表19. Do not hide base class methods 不要隐藏(使用或者不使用new)基类的方法20. Do not nest generic types in member signatures 不要在成员的签名(参数或

5、者返回值)中嵌套泛型类21. Do not override operator equals on reference types 不要在引用类型中重载=操作符22. Do not pass types by reference 不要使用引用(ref or out)传递类型23. Enum Storage should be Int32 枚举应该是Int32 类型的24. Enumerators should be strongly typed 枚举器应该是强类型的25. Enums should have zero value 枚举应该具有0 值26. Generic methods sho

6、uld provide type parameter 泛型类的方法应该提供类型参数27. ICollection implementations have strongly typed members 集合接口的实现中应该使用强类型的成员28. Implement standard exception constructors 自定义的异常应该实现异常类的四个标准构造方法29. Indexers should not be multidimensional 索引不应该是多维的30. Interface methods should be callable by child types 接口方法

7、应该可以被子类调用31. Lists are strongly typed 表应该是强类型的32. Mark assemblies with assembly version 用程序集版本标示程序集33. Mark assemblies with CLSCompliant 使用 CLSCompliant 特性标示程序集34. Mark assemblies with ComVisible 使用System.Runtime.InteropServices.ComVisibleAttribute 特性标示程序集35. Mark attributes with AttributeUsageAttri

8、bute 使用AttributeUsageAttribute 特性标示特性类36. Mark enums with FlagsAttribute 含有组合的枚举应该使用FlagsAttribute 特性标示,相反则不应该37. Members should not expose certain concrete types 成员(返回值或者参数)不应该暴露具体类型,尽量使用接口38. Move pinvokes to native methods class 将调用移到本地方法类(不是很理解)39. Nested types should not be visible 嵌套类型不应该是可见的4

9、0. Override methods on comparable types 可比较类型应该重写equals 等方法41. Override operator equals on overriding add and subtract 在重写 +和 -运算的时候应该同时重写=操作符42. Properties should not be write only 属性不应该是只写的43. Provide ObsoleteAttribute message 过时的成员应该使用ObsoleteAttribute 特性标示,并提供相应的Message 提示使用者44. Replace repetiti

10、ve arguments with params array 使用参数数组代替重复的参数45. Static holder types should be sealed 仅含有静态成员的类型应该声明为封闭的46. Static holder types should not have constructors 仅含有静态成员的类型应该具有构造方法47. String uri overloads call system uri overloads 使用 string 类型的 uri 参数的重载应调用系统的使用URI 类型参数的重载48. Types should not extend certa

11、in base types 类型不应该从具体的类(已经过派生的类)继承, 比如异常类不应该从ApplicationException继承,而应该从System.Exception 继承49. Types that own disposable fields should be disposable 含有可释放成员的类型应该是可以释放的(实现IDisposable 接口)50. Types that own native resources should be disposable 使用了非托管资源的类型应该是可以释放的(实现IDisposable 接口)51. Uri parameters s

12、hould not be strings Uri 参数不应该是string 类型的52. Uri properties should not be strings Uri 属性不应该是string 类型的53. Uri return values should not be strings Uri 类型的返回值不应该是string 类型的54. Use events where appropriate 在适当的时候使用事件55. Use generic event handler instances 使用泛型的事件处理器实例56. Use generics where appropriate

13、在适当的时候使用范型57. Use integral or string argument for indexers 索引器应该使用整数或者字符串类型的参数58. Use properties where appropriate 在适当的时候使用属性(而不是以Get 或者 Set 开头的方法)59. Validate arguments of public methods 对 public 的方法的参数应该在方法开头处进行检验(比如是否为null 的检验)二、Globalization (全球化)1. Avoid duplicate accelerators 避免在顶层控件中使用重复的快捷键(

14、加速键)2. Do not hardcode locale specific strings 不要对本地的特殊字符串(比如特殊的系统路径)进行硬编码3. Do not pass literals as localized parameters 不要把文本作为需要本地化的参数直接传递(尽量使用资源文件)4. Set locale for data types 为某些数据类型设定区域和语言属性(DataSet 和 DataTable 的 locale 属性)5. Specify CultureInfo 指定文化信息 (地域和语言信息) ,在调用接受System.Globalization.Cult

15、ureInfo 类型参数的方法时应该传递文化信息6. Specify IFormatProvider 指定格式供应器,在调用接受System.IFormatProvider 类型参数的方法时应该传递格式供应器7. Specify MessageBoxOptions 指 定MessageBox的 选 项 , 在 调 用MessageBox.Show方 法 时 应 该 传 递System.Windows.Forms.MessageBoxOptions ,特别在某些从右向左阅读习惯的区域三、Interoperability (互操作性)1. Auto layout types should not

16、be ComVisible 自动布局的类型不应该对Com可见(设置System.Runtime.InteropServices.ComVisibleAttribute特性为 false)2. Avoid int64 arguments for VB6 clients 避免使用int64 类型,如果成员可能被Visual Basic 6 COM clients调用3. Avoid non-public fields in ComVisible value types 避免在一个标记有ComVisible 特性的值类型里面包含非公有的实例域4. Avoid overloads in ComVisible interfaces 避免在一个标记有ComVisible 特性的接口内声明重载5. Avoid static members in ComVisible types 避免在一个标记有ComVisible 特性的类型6. Call GetLastError immediately after pinvoke 进行 pinvoke 以后应该立即使用GetLastError 读取错误信息7

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号