Skip to content

Gendarme.Rules.Naming.AvoidRedundancyInTypeNameRule(git)

Sebastien Pouliot edited this page Mar 2, 2011 · 1 revision

AvoidRedundancyInTypeNameRule

Assembly: Gendarme.Rules.Naming
Version: git

Description

This rule will fire if a type is prefixed with the last component of its namespace. Using prefixes like this makes type names more verbose than they need to be and makes them harder to use with tools like auto-complete. Note that an exception is made if removal of the prefix would cause an ambiguity with another type. If this is the case the rule will not report a defect.

Examples

Bad example:

namespace Foo.Lang.Compiler {
    public class CompilerContext {
    }
}
using Foo.Lang;
...
Compiler.CompilerContext context = new Compiler.CompilerContext ();
using Foo.Lang.Compiler;
...
CompilerContext context = new CompilerContext ();

Good example:

namespace Foo.Lang.Compiler {
    public class Context {
    }
}
using Foo.Lang;
...
Compiler.Context context = new Compiler.Context ();
using Foo.Lang.Compiler;
...
Context context = new Context ();

Another good example (more meaningful term in the context of the namespace):

namespace Foo.Lang.Compiler {
    public class CompilationContext {
    }
}

Source code

You can browse the latest source code of this rule on github.com

Clone this wiki locally