- Home /
Namespaces that correspond to file location
I would like to use "namespaces that correspond to file location" rule for my Unity project, but I cannot think about subdirectory names.
For example, I am having this script in this directory hierachy:
Scripts->Patterns->Singleton->Singleton.cs
So the namespace according to the rule above will be Scripts.Patterns.Singleton
But it intersects with a script class name and this is not ok for me. How I can name subdirectory for Singleton.cs?
Answer by sacredgeometry · Apr 12, 2020 at 03:39 PM
You wouldnt have a namespace called Singleton
you would put the Singleton
class in the Patterns
namespace. If you had multiple singleton implementations you could create a Singletons
namespace instead.
I would argue that Patterns
isnt a particularly good namespace either but its better than Singleton.
Yes, but this way I will have a directory named Patterns that will have all patern scripts: Singleton.cs, Pool.cs, PoolObject.cs etc in the same directory, I wanna avoid this
Why do you want to avoid that? Have a single folder for each script and a single namespace is the opposite of why those two mechanisms exist.
Well, then its against the standart Resharper rule - Namespaces should correspond to file location. So if I make folders for scripts so I dont use these folder names in my namespace then I break the rule.
Your answer
Follow this Question
Related Questions
Any reason not to use namespace for scripts for asset store 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Mac/PC differences in directory symbols '\' and '/' 2 Answers