Export (0) Print
Expand All

CA1715: Identifiers should have correct prefix

TypeName

IdentifiersShouldHaveCorrectPrefix

CheckId

CA1715

Category

Microsoft.Naming

Breaking Change

Breaking - when fired on interfaces.

Non-breaking - when raised on generic type parameters.

The name of an externally visible interface does not start with an uppercase 'I'.

-or-

The name of a generic type parameter on an externally visible type or method does not start with an uppercase 'T'.

By convention, the names of certain programming elements start with a specific prefix.

Interface names should start with an uppercase 'I' followed by another uppercase letter. This rule reports violations for interface names such as 'MyInterface' and 'IsolatedInterface'.

Generic type parameter names should start with an uppercase 'T' and optionally may be followed by another uppercase letter. This rule reports violations for generic type parameter names such as 'V' and 'Type'.

Naming conventions provide a common look for libraries that target the common language runtime. This reduces the learning curve that is required for new software libraries, and increases customer confidence that the library was developed by someone who has expertise in developing managed code.

Rename the identifier so that it is correctly prefixed.

Do not suppress a warning from this rule.

The following example shows an incorrectly named interface.

using namespace System;

namespace Samples
{
    public interface class Book     // Violates this rule
    {
        property String^ Title
        {
            String^ get();
        }
        void Read();
    };
}

The following example fixes the previous violation by prefixing the interface with 'I'.

using namespace System;

namespace Samples
{
    public interface class IBook  // Fixes the violation by prefixing the interface with 'I'
    {
        property String^ Title
        {
            String^ get();
        }
        void Read();
    };
}

The following example shows an incorrectly named generic type parameter.

using namespace System;

namespace Samples
{
    generic <typename Item>     // Violates this rule 
    public ref class Collection
    {

    };
}

The following example fixes the previous violation by prefixing the generic type parameter with 'T'.

using namespace System;

namespace Samples
{
    generic <typename TItem>  // Fixes the violation by prefixing the generic type parameter with 'T' 
    public ref class Collection
    {

    };
}
Show:
© 2014 Microsoft