C
C#β€’2y ago
Sygmond

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).
30 Replies
Pobiega
Pobiegaβ€’2y ago
I see no question attached to this post... but I'm guessing you want ideas on how to solve this.
Sygmond
Sygmondβ€’2y ago
Yes πŸ™‚
Pobiega
Pobiegaβ€’2y ago
Unfortunately, you've already nailed it - its either via a tool, or manual. They both have ups and downs. Perhaps refactor the folder structure before doing the rider fix?
Sygmond
Sygmondβ€’2y ago
That's a nice idea.
ero
eroβ€’2y ago
Hm? There's a code cleanup thing for this editorconfig Whichever
Sygmond
Sygmondβ€’2y ago
I can do it via editconfig and apply to the whole solution and name the namespaces as folder structure. Do you have in mind another editorconfig rule for this?
ero
eroβ€’2y ago
If you have set such a rule, perhaps running dotnet format will apply it?
Sygmond
Sygmondβ€’2y ago
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 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. that's why I want to fix the namespaces, is a total disaster and I'm pretty fixed on consistency :))
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
Sygmond
Sygmondβ€’2y ago
thanks Do you recommend having the namespaces the same as folder structure?
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
Sygmond
Sygmondβ€’2y ago
I want the same. I feel better now :))
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
Sygmond
Sygmondβ€’2y ago
Thank you all, I will be starting now to organize them all.
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
Sygmond
Sygmondβ€’2y ago
πŸ˜„
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
Sygmond
Sygmondβ€’2y ago
893 .cs files 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.
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
Sygmond
Sygmondβ€’2y ago
Thank you. That is very very useful.
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
Sygmond
Sygmondβ€’2y ago
In my previous project the TL said not to go too deep :)) now I understand why
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
Sygmond
Sygmondβ€’2y ago
Do you recommend ERP in project name or Erp?
Unknown User
Unknown Userβ€’2y ago
Message Not Public
Sign In & Join Server To View
Sygmond
Sygmondβ€’2y ago
ok
Teddy
Teddyβ€’2y ago
Microsoft.AspNetCore.Hosting.csproj Even though it's ASP they go with Asp
Sygmond
Sygmondβ€’2y ago
I've seen now that instead of API they also use Api. I go with the convention
Teddy
Teddyβ€’2y ago
But your company is free to create their own naming conventions πŸ€·β€β™‚οΈ
Sygmond
Sygmondβ€’2y ago
I created it now :))