Repository navigation
|
is there a way to check if the namespace of a project is withing the root namespace? |
Replies: 1 comment
|
Yes. If you mean “the namespace should be the project's RootNamespace plus the file's folder path,” the built-in .NET rule IDE0130 checks that (it's not a Roslynator-specific rule). For example, with root namespace Add this to [*.cs]
dotnet_style_namespace_match_folder = true
dotnet_diagnostic.IDE0130.severity = warningFor command-line build enforcement, also set <ItemGroup>
<CompilerVisibleProperty Include="RootNamespace" />
<CompilerVisibleProperty Include="ProjectDir" />
</ItemGroup>See IDE0130 docs and code-style build enforcement. If you only want to check that the namespace starts with a prefix, regardless of folder structure, IDE0130 is stricter than that. |
Yes. If you mean “the namespace should be the project's RootNamespace plus the file's folder path,” the built-in .NET rule IDE0130 checks that (it's not a Roslynator-specific rule). For example, with root namespace
Root, a file underData/Example.csshould useRoot.Data.Add this to
.editorconfigto report mismatches as warnings:For command-line build enforcement, also set
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>. The rule needsRootNamespaceandProjectDiras compiler-visible properties outside Visual Studio: