C#
C#

help

Root Question Message

Sygmond
Sygmond8/12/2022
Inconsistent namespaces

(Solved) I'm currently working on a solution with a lot of subfolders and I noticed that the namespaces of .cs files are not reflecting the folder structure.
On top of that, in some projects, i.e. the files inside "Commands" and "Queries" have the same namespace and in other projects they have wrong namespace like ending in "Messages" while the folder name is Queries.

I would be able to fix this automatically in Rider by naming all namespaces according to folder structure but I'm afraid I will end up having hundreds of 10 levels long namespaces and usings.

Other solution is to go in every file and understand the pattern that was used in naming the namespaces and correct the wrong ones (this will take a lot of time).
Pobiega
Pobiega8/12/2022
I see no question attached to this post... but I'm guessing you want ideas on how to solve this.
Sygmond
Sygmond8/12/2022
Yes 🙂
Pobiega
Pobiega8/12/2022
Unfortunately, you've already nailed it - its either via a tool, or manual.
Pobiega
Pobiega8/12/2022
They both have ups and downs.
Pobiega
Pobiega8/12/2022
Perhaps refactor the folder structure before doing the rider fix?
Sygmond
Sygmond8/12/2022
That's a nice idea.
Ero
Ero8/12/2022
Hm? There's a code cleanup thing for this
Ero
Ero8/12/2022
editorconfig
Ero
Ero8/12/2022
Whichever
Sygmond
Sygmond8/12/2022
I can do it via editconfig and apply to the whole solution and name the namespaces as folder structure.
Sygmond
Sygmond8/12/2022
Do you have in mind another editorconfig rule for this?
Ero
Ero8/12/2022
If you have set such a rule, perhaps running dotnet format will apply it?
Sygmond
Sygmond8/12/2022
that is going well, I tried it already, but it creates long namespaces as there are 10 level subfolders.
Maybe this is better than having inconsistency
Sygmond
Sygmond8/12/2022
Two different projects i.e.Company.App.Access.User and Company.App.Access.Implementation have the same namespace Company.App.Access for files in the root folder but different for the ones in subfolders.
Sygmond
Sygmond8/12/2022
that's why I want to fix the namespaces, is a total disaster and I'm pretty fixed on consistency :))
Message Not Public

Sign In and Join Server To See

8/12/2022
Message Not Public

Sign In and Join Server To See

8/12/2022
Message Not Public

Sign In and Join Server To See

8/12/2022
Sygmond
Sygmond8/12/2022
thanks
Sygmond
Sygmond8/12/2022
Do you recommend having the namespaces the same as folder structure?
Message Not Public

Sign In and Join Server To See

8/12/2022
Sygmond
Sygmond8/12/2022
I want the same. I feel better now :))
Message Not Public

Sign In and Join Server To See

8/12/2022
Message Not Public

Sign In and Join Server To See

8/12/2022
Sygmond
Sygmond8/12/2022
Thank you all, I will be starting now to organize them all.
Message Not Public

Sign In and Join Server To See

8/12/2022
Sygmond
Sygmond8/12/2022
😄
Message Not Public

Sign In and Join Server To See

8/12/2022
Sygmond
Sygmond8/12/2022
893 .cs files
Sygmond
Sygmond8/12/2022
that's why I like rules, so that in the future I don't have to figure it out. I took the project from someone else and I have to continue development.
Message Not Public

Sign In and Join Server To See

8/12/2022
Message Not Public

Sign In and Join Server To See

8/12/2022
Sygmond
Sygmond8/12/2022
Thank you. That is very very useful.
Message Not Public

Sign In and Join Server To See

8/12/2022
Message Not Public

Sign In and Join Server To See

8/12/2022
Sygmond
Sygmond8/12/2022
In my previous project the TL said not to go too deep :)) now I understand why
Message Not Public

Sign In and Join Server To See

8/12/2022
Sygmond
Sygmond8/12/2022
Do you recommend ERP in project name or Erp?
Message Not Public

Sign In and Join Server To See

8/12/2022
Sygmond
Sygmond8/12/2022
ok
Message Not Public

Sign In and Join Server To See

8/12/2022
Message Not Public

Sign In and Join Server To See

8/12/2022
Sygmond
Sygmond8/12/2022
I've seen now that instead of API they also use Api. I go with the convention
Message Not Public

Sign In and Join Server To See

8/12/2022
Sygmond
Sygmond8/12/2022
I created it now :))
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy