FxCop 国际化和互操作性规则

二、 Globalization(全球化)
1. Avoid duplicate accelerators
避免在顶层控件中使用重复的快捷键(加速键)

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.CultureInfo 类型参数的方法时应该传递文化信息

6. Specify IFormatProvider
指定格式供应器,在调用接受System.IFormatProvider 类型参数的方法时应该传递格式供应器

7. Specify MessageBoxOptions
指定MessageBox的选项,在调用MessageBox.Show方法时应该传递System.Windows.Forms.MessageBoxOptions,特别在某些从右向左阅读习惯的区域
 
三、 Interoperability(互操作性)
1. Auto layout types should not 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. Com registration methods should be matched
Com注册方法(标记有System.Runtime.InteropServices.ComRegisterFunctionAttribute特性的方法)应该是配对的(同时具有一个标记有System.Runtime.InteropServices.ComUnregisterFunctionAttribute的方法与之匹配)

8. Com registration methods should not be visible
Com注册方法应该是不可见的

9. Com visible type base types should be ComVisible
标记有ComVisible特性的类型的基类同样应从标记有ComVisible特性的类继承

10. Com visible types should be creatable
标记有ComVisible特性的类型应该能够使用默认构造器构造

11. Declare PInvokes correctly
正确定义PInvokes

12. Do not use AutoDual ClassInterfaceType
不要把System.Runtime.InteropServices.ClassInterfaceAttribute特性的值设置为System.Runtime.InteropServices.ClassInterfaceType.AutoDual

13. Mark boolean pinvoke arguments with MarshalAs
布尔型的pinvoke参数应该使用System.Runtime.InteropServices.MarshalAsAttribute特性标记

14. Mark ComSource interfaces as IDispatch
将System.Runtime.InteropServices.ComSourceInterfacesAttribute特性标记为System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIDispatch.

15. PInvoke entry points should exist
Pinvoke应该存在入口点

16. PInvokes should not be visible
Pinvoke应该是可见的

posted @   quitgame  阅读(512)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示