Reputation:
I'm fairly new to C# and I'm trying to structure my simple web API project. One of the things I want to do is group all of my stuff under the namespace [Company].[Project]
, and then further slice that into individual .[Feature]
slices. For example, I'd like to do MyCompany.MyProject.MusicHandling
for a part of it that handles serialization, deserialization, and talking to the music part of the service.
This seems natural:
namespace MyCompany.MyProject {
namespace MusicHandling {
// Classes
}
}
For every class file I want in this namespace. However, when I do this StyleCop complains about SA1403: A C# Document Can Only Contain a Single Namespace
.
Okay, I think, no problem:
namespace MyCompany.MyProject.MusicHandling {
// classe
}
Now it's complaining again! This time it's Namespace does not correspond to file location, should be 'MyCompany.MyProject'
. SIGH.
I try to follow a linter with a new language and set it extra strict so I learn best practices as I code. How should I structure these submodules of code so it makes logical sense for the user of my library?
Upvotes: 0
Views: 275
Reputation: 38087
The new complaint is that Style Cop expects that files in a namespace are in a folder structure matching the namespace. Basically it takes your project's root namespace and assumes all files in that namespace are at the root of the project. Any namespaces under the root should have a matching folder in which files that contains classes in that namespace live.
Upvotes: 1