We recommend using Visual Studio 2017

CA1020: Avoid namespaces with few types


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at CA1020: Avoid namespaces with few types.

|Breaking Change|Breaking|

A namespace other than the global namespace contains fewer than five types.

Make sure that each of your namespaces has a logical organization, and that a valid reason exists to put 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 for use in the same application. Therefore, they are 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.

System_CAPS_ICON_note.jpg 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.

To fix a violation of this rule, try to combine namespaces that contain just a few types into a single namespace.

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