Naming Namespace
ID |
csharp.naming_namespace |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
CSharp |
Tags |
naming |
Description
Reports C# namespace declarations whose name does not follow the PascalCase
convention. Every dot-separated segment must start with an uppercase letter and
contain no underscores.
Applies to both block-form (namespace Foo.Bar { … }) and file-scoped
(namespace Foo.Bar;) namespace declarations.
Rationale
The .NET design guidelines specify PascalCase for namespace names. Consistent
namespace casing is important because the namespace name appears in every
using directive and qualified reference; lowercase or snake_case segments
stand out as foreign.
namespace Acme.Billing { } // OK
namespace acme.billing { } // FLAW — lowercase segments
namespace Acme.bad_segment { } // FLAW — underscore + lowercase
namespace Acme.Billing.Reports { } // OK
namespace MyCompany; // OK (file-scoped)
namespace myCompany.tooling; // FLAW — lowercase segments
Remediation
Rename each namespace segment to PascalCase: capitalize the first letter of
each word and remove underscores. For example, rename acme.billing to
Acme.Billing.
Configuration
properties:
# Segments accepted verbatim regardless of casing (platform brand names).
allowedSegments: [iOS, macOS, tvOS, watchOS]
Segments listed in allowedSegments are accepted as-is. The default covers Apple
platform brand names whose casing is fixed by convention (MyApp.iOS in
Xamarin / .NET MAUI solutions).