Avoid naming types and namespaces with the same identifier

Rule ND2014 Naming Conventions

Warns when a type and a namespace share the same name (e.g. type Environment and namespace Foo.Environment): tedious compiler resolution collisions and less readable code.

How to fix

Rename the concerned type or namespace.

CQLinq source

This rule is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.

// <Name>Avoid naming types and namespaces with the same identifier</Name>
// <Id>ND2014:AvoidNamingTypesAndNamespacesWithTheSameIdentifier</Id>

warnif count > 0
let hashsetShortNames = JustMyCode.Namespaces.Where(n => n.Name.Length > 0).Select(n => n.SimpleName).ToHashSetEx()

from t in JustMyCode.Types
where hashsetShortNames.Contains(t.Name)
select new { 
   t, 
   namespaces = Namespaces.Where(n => n.SimpleNameEquals(t.Name)),
   Debt = 12.ToMinutes().ToDebt(),
   Severity = Severity.High
}

//<Expl>
// The *{0}* shares the same name as the *{1}*.
// This situation is ambiguous and can lead to complex compilation errors.
//</Expl>

//<Desc>
// Warns when a type and a namespace share the same name (e.g. type
// *Environment* and namespace *Foo.Environment*): tedious compiler
// resolution collisions and less readable code.
//</Desc>

//<HowToFix>
// Rename the concerned type or namespace.
//</HowToFix>

Naming Conventions: all 23 items