简体   繁体   中英

C# Naming Conventions of namespaces

At work, they've been quite elaborate with their naming of namespaces (before my time). A typical namespace could be

CompanyName.SubCompanyName.DepartmentName.ProjectName.UniqueProjectName.ProjectName.FilteredProjectName

Sadly, I'm not joking. The issue is, despite being some clarity as to where the projects live it's just so noisy; I want to shorten it.

I want to use using keyword (in regards to declaring which namespaces are to be used) and then equals symbol to use a namespace alias. The issue now turns into ambiguity between a namespace declaration and a class's property. For example

Project.Message

As it stands, we have no indication if Project is the name of a static class, a namespace or the name of an already initialised object (although the word this. would help clarify it).

So, with that background, my question is about naming conventions. For me, it would make sense to use the Hungarian style naming conventions (which I know is now considered fairly outdated these days) so I could do something like

using nsProject = CompanyName.SubCompanyName.DepartmentName.ProjectName.UniqueProjectName.ProjectName.FilteredProjectName

Please note, I've prefixed it with ns (namespace). Therefore, if the code looks like either of the following, there is at least some clarity:

this.Project.Message
nsProject.Message
Project.Message

The 3 above examples are fairly clear now: the first has already been declared in the project, the second is the namespace and the third is probably a static method call.

Does any one have any comments about this approach; am I reinventing the wheel (are there already guidelines in place) or does any one have a different opinion on what can be done?

EDIT

Another reason for wanting to use Alias's is the current namespaces do not match (or have any significance in some places) to the folder structure. So not only do I want to ensure clarity between what type of object/namespace is being used, but my Alias will also be a guide as to the folder location. I know, this probably reads as hacking etc but (as per comments in this post) it is the first stage of many.

I wouldn't know of any "Official" guidelines, but whenever I alias a namespace I usually use a contraction of the Company and the Project. This would result in (using your example):

this.Project.Message.Send();
CompanyProject.Message.Send();
Project.Message.Send();

I prefer postfixing above hungarian btw (subjective I know).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM