C
C#3y 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
Pobiega3y ago
I see no question attached to this post... but I'm guessing you want ideas on how to solve this.
Sygmond
SygmondOP3y ago
Yes 🙂
Pobiega
Pobiega3y 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
SygmondOP3y ago
That's a nice idea.
ero
ero3y ago
Hm? There's a code cleanup thing for this editorconfig Whichever
Sygmond
SygmondOP3y 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
ero3y ago
If you have set such a rule, perhaps running dotnet format will apply it?
Sygmond
SygmondOP3y 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 User3y ago
Message Not Public
Sign In & Join Server To View
Sygmond
SygmondOP3y ago
thanks Do you recommend having the namespaces the same as folder structure?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Sygmond
SygmondOP3y ago
I want the same. I feel better now :))
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Sygmond
SygmondOP3y ago
Thank you all, I will be starting now to organize them all.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Sygmond
SygmondOP3y ago
😄
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Sygmond
SygmondOP3y 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 User3y ago
Message Not Public
Sign In & Join Server To View
Sygmond
SygmondOP3y ago
Thank you. That is very very useful.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Sygmond
SygmondOP3y ago
In my previous project the TL said not to go too deep :)) now I understand why
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Sygmond
SygmondOP3y ago
Do you recommend ERP in project name or Erp?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Sygmond
SygmondOP3y ago
ok
Teddy
Teddy3y ago
Microsoft.AspNetCore.Hosting.csproj Even though it's ASP they go with Asp
Sygmond
SygmondOP3y ago
I've seen now that instead of API they also use Api. I go with the convention
Teddy
Teddy3y ago
But your company is free to create their own naming conventions 🤷‍♂️
Sygmond
SygmondOP3y ago
I created it now :))
Want results from more Discord servers?
Add your server