Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-4041

Type names should not match namespaces

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Change the name of type '{0}' to be different from an existing framework namespace.
    • Highlighting:
      Hide

      Type declaration

      Show
      Type declaration
    • Default Severity:
      Minor
    • Impact:
      Low
    • Likelihood:
      Low
    • Covered Languages:
      C#
    • Irrelevant for Languages:
      ABAP, C, C++, Cobol, CSS, Flex, HTML, Java, JavaScript, Objective-C, PHP, PL/I, PL/SQL, Python, RPG, Swift, T-SQL, TypeScript, VB.Net, VB6, XML
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      2min
    • Analysis Scope:
      Main Sources, Test Sources
    • FxCop:
      TypeNamesShouldNotMatchNamespaces, CA1724

      Description

      When a type name matches the name of a publicly defined namespace, for instance one in the .NET framework class library, it leads to confusion and makes the library that much harder to use.

      This rule raises an issue when a name of a public type matches the name of a .NET Framework namespace, or a namespace of the project assembly, in a case-insensitive comparison.

      Noncompliant Code Example

      using System;
      
      namespace MyLibrary
      {
        public class Text   // Noncompliant: Collides with System.Text
        {
        }
      }
      

      Compliant Solution

      using System;
      
      namespace MyLibrary
      {
        public class MyText
        {
        }
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              jeanchristophe.collet Jean-Christophe Collet (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: