Share via


CA1020: Avoid namespaces with few types

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Item Value
RuleId CA1020
Category Microsoft.Design
Breaking change Breaking

Cause

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

Note

This rule has been deprecated. For more information, see Deprecated rules.

Rule description

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.

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 just a few types into a single namespace.

When to suppress warnings

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.