Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

c# - Should the folders in a solution match the namespace?

Should the folders in a solution match the namespace?

In one of my teams projects, we have a class library that has many sub-folders in the project.

Project Name and Namespace: MyCompany.Project.Section.

Within this project, there are several folders that match the namespace section:

  • Folder Vehicles has classes in the MyCompany.Project.Section.Vehicles namespace
  • Folder Clothing has classes in theMyCompany.Project.Section.Clothing namespace
  • etc.

Inside this same project, is another rogue folder

  • Folder BusinessObjects has classes in the MyCompany.Project.Section namespace

There are a few cases like this where folders are made for "organizational convenience".

My question is: What's the standard? In class libraries do the folders usually match the namespace structure or is it a mixed bag?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Also, note that if you use the built-in templates to add classes to a folder, it will by default be put in a namespace that reflects the folder hierarchy.

The classes will be easier to find and that alone should be reasons good enough.

The rules we follow are:

  • Project/assembly name is the same as the root namespace, except for the .dll ending
  • Only exception to the above rule is a project with a .Core ending, the .Core is stripped off
  • Folders equals namespaces
  • One type per file (class, struct, enum, delegate, etc.) makes it easy to find the right file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...