Question

I'm working on a project in C# .NET (Visual Studio 2010) with a number of generated partial classes, metadata classes, etc. (if you know Entity Framework, you know what I mean)

My question pertains to the practice of correlating namespaces with directories, whereby each directory denotes a sub-namespace.

Now, I'd like to move the metadata classes into a sub-directory, purely for organizational purposes. Since partial classes must exist within the same namespace, the Metadata sub-directory can no longer denote a namespace (otherwise it'd break the partial classes) I'd be departing from the aforementioned practice; not a big deal, but I like sticking to a standard.

Is there a convention to denote that a given directory is purely organizational?

Off-hand, prefixing the directory name with "." (dot) or "_" (underscore) seems appropriate, the former more than the latter since it would result in an invalid namespace name.


@Pheonixblade9, something like this:

:
|
+- ProjectFolder/
|   +- App.config
|   +- Packages.config
|   +- ClassA.cs
|   +- ClassB.cs
|   +- ClassC.cs
|   +- ClassD.cs
|   +- Metadata/
|   |   +- ClassA.Metadata.cs  \
|   |   +- ClassB.Metadata.cs   \ These are the partial classes that shouldn't
|   |   +- ClassC.Metadata.cs   / be namespaced differently than their respective
|   |   +- ClassD.Metadata.cs  /  partials in the parent folder
:   :
Was it helpful?

Solution 2

Despite @JohanLarsson providing the correct answer for 2012+, I've opted for the . prefix on the directory:

:
+- ClassC.cs
+- ClassD.cs
+- .Metadata/
|   +- ClassA.Metadata.cs
|   +- ClassB.Metadata.cs
:   :

This renders the namespace name provided to classes created in that folder invalid. It's more of an implicit indicator than an explicit rule as I'd have preferred (and as @JohanLarsson's answer provides) but then again, I'm the sucker running 2010.

I'm still open to answers, and will gladly change acceptance to something better.

OTHER TIPS

  1. Select the folder in solution explorer
  2. In properties set NameSpace Provider to false
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top