[FXCOP.设计规则]5. 避免命名空间中包含太少的类型
来源:互联网 发布:白色丝袜淘宝 编辑:程序博客网 时间:2024/04/28 08:48
原文引用:
Avoid namespaces with few types
TypeName:
AvoidNamespacesWithFewTypes
CheckId:
CA1020
Category:
Microsoft.Design
Message Level:
Warning
Certainty:
50%
Breaking Change:
Breaking
Cause: A namespace other than the global namespace contains fewer than five types.
Rule Description
Make sure that there is a logical organization to each of your namespaces, and that there is a valid reason for putting types in a sparsely populated namespace. Namespaces should contain types that are used together in most scenarios. When their applications are mutually exclusive, types should be located in separate namespaces. For example, the System.Web.UI namespace contains types that are used in Web applications, and the System.Windows.Forms namespace contains types that are used in Windows-based applications. Even though both namespaces have types that control aspects of the user interface, these types are not designed to be used in the same application, and are therefore located in separate namespaces. Careful namespace organization can also be helpful because it increases the discoverability of a feature. By examining the namespace hierarchy, library consumers should be able to locate the types that implement a feature.
Note: Design-time types and permissions should not be merged into other namespaces to comply with this guideline. These types belong in their own namespaces below your main namespace, and the namespaces should end in .Design and .Permissions, respectively.
How to Fix Violations
To fix a violation of this rule, try to combine namespaces that contain a small number of types into a single namespace.
When to Exclude Messages
It is safe to exclude a message from this rule when the namespace does not contain types that are used with the types in your other namespaces. It is also safe to exclude a violation if there are fewer than five types in the library.
引发原因:
一个非全局的命名空间内少于5个类型。
规则描述:
确保你命名空间有良好的逻辑结构;如非必要,不要把类型放在一个新的命名空间里。
命名空间应该包含一组经常被一起使用的类型。如果几个类型的使用场景是互斥的,他们应该被放在不同的命名空间中。例如:System.Web.UI命名空间内的类型被Web程序使用,System.Windows.Forms命名空间内的类型则被Windows-based程序使用。尽管这两个命名空间都包含控制UI的类型,但这些类型的应用场景并不一样,因此,它们被分置于不同的命名空间中。
精心组织的命名空间结构同样很有帮助,它增加了用户发现类库功能的能力,通过查询命名空间的层次结构,类库用户很容易知道将实现某个功能的类型置于何处。
备注:设计时(Design-time)类型和许可相关的类型(permissions)将不符合这条策略,它们将在主命名空间内拥有独立的命名空间。并且分别以”.Design”和”.Permissions”结尾。
修复问题:
如果需要修复这个问题,可以尝试将几个小的命名空间合并到一个命名空间。
可否忽略:
如果一个命名空间内的类型不与其它命名空间内的类型同时使用,可以忽略该规则引发的警告。如果类库内总共不到5个类型,也可以忽略这条规则。
- [FxCop.设计规则]5. 避免命名空间中包含太少的类型
- [FXCOP.设计规则]5. 避免命名空间中包含太少的类型
- [FxCop.设计规则]10. 类型应该被声明在命名空间中
- [FxCop.设计规则]3.避免定义空的接口
- [FxCop.设计规则]4. 避免太多的范型参数
- [FxCop.设计规则] 3. 避免定义空的接口
- [FxCop.设计规则]4. 避免太多的范型参数
- Microsoft FxCop 的设计规则
- Microsoft FxCop 的设计规则 .
- [FxCop.设计规则]6. 避免使用输出参数
- [FxCop.设计规则]2. 程序集应该拥有有效的强命名
- [FxCop.设计规则]8. 也许参数类型应该是基类型
- FxCop 设计规则
- FxCop 设计规则
- FxCop 设计规则
- [FxCop.设计规则]1. 抽象类型不应具有构造函数
- C# 中常用数据类型与控件类型的命名规则
- C# 中常用数据类型与控件类型的命名规则
- 男生女生谈恋爱前必备的条件
- 网站建设合同书
- 房价肯定会跌的
- ,顺流逆流。
- 新装VS2005无法打开用IIS配置的web页面的解决方法
- [FXCOP.设计规则]5. 避免命名空间中包含太少的类型
- 又过了1天
- automation不能创建新对象-
- 图档同学请注意:期末论文应写在白纸上,注意不是白卷,不是格纸。
- Blog的TrackBack功能的使用方法
- C#中string转换DataTime以及计算日期差
- 今天是06年06月06日.是个666大顺的吉祥日子 是个千年等一回的日子,在这个美好 的日子里 祝你在家顺,在外顺,心顺意顺;事业顺,前程顺,一顺百顺;天地顺,人情顺,风调雨顺;现在顺,将来顺,一帆风顺,恭祝万事顺利!! /:Y/:-F
- 我的Visual C++入门之路——N次失败与1次成功
- SQL Server管理常用SQL语句