다음을 통해 공유


Avoid namespaces with few types

TypeName

AvoidNamespacesWithFewTypes

CheckId

CA1020

Category

Microsoft.Design

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.

NoteNote

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 Warnings

It is safe to exclude a warning from this rule when the namespace does not contain types that are used with the types in your other namespaces.