Nested types should not be visible
Visual Studio Team System
Nested types should not be visible

TypeName

NestedTypesShouldNotBeVisible

CheckId

CA1034

Category

Microsoft.Design

Breaking Change

Breaking

An externally visible type contains an externally visible type declaration. Nested enumerators are exempt from this rule.

A nested type is a type declared within the scope of another type. Nested types are useful for encapsulating private implementation details of the containing type. Used for this purpose, nested types should not be externally visible.

Do not use externally visible nested types for logical grouping or to avoid name collisions; instead, use namespaces.

Nested types include the notion of member accessibility, which is not clearly understood by all audiences.

To fix a violation of this rule, if the nested type is not meant to be externally visible, change the type's accessibility. Otherwise, remove the nested type from its parent. If the purpose of the nesting is to categorize the nested type, use a namespace to create the hierarchy instead.

Do not exclude a warning from this rule.

The following example shows a type that violates the rule.

Visual Basic
Imports System

Namespace DesignLibrary

    Class ParentType

        Public Class NestedType
            Sub New()
            End Sub
        End Class

        Sub New()
        End Sub

    End Class

End Namespace
C#
using System;

namespace DesignLibrary
{
    internal class ParentType
    {
        public class NestedType
        {
            public NestedType()
            {
            }
        }

        public ParentType()
        {
            NestedType nt = new NestedType();
        }
    }
}
C++
using namespace System;

namespace DesignLibrary
{
    public ref class ParentType
    {
    public:
        ref class NestedType
        {
        public:
            NestedType()
            {
            }
        };

        ParentType()
        {
            NestedType^ nt = gcnew NestedType();
        }
    };
}
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Nested enumerators is detected      fafanoulele   |   Edit   |   Show History
In the following code, enumeration "Inner" is detected :
public class InnerEnum
{
public enum Inner
{
PIERRE,
PAUL,
JACQUES,
}
}

is it possible to ignore this case?
Processing
Page view tracker