解决方案中的文件夹是否应该与命名空间匹配? [英] Should the folders in a solution match the namespace?

查看:23
本文介绍了解决方案中的文件夹是否应该与命名空间匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案中的文件夹是否应与命名空间匹配?

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.

项目名称和命名空间:MyCompany.Project.Section.

Project Name and Namespace: MyCompany.Project.Section.

在这个项目中,有几个文件夹与命名空间部分匹配:

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

  • 文件夹 VehiclesMyCompany.Project.Section.Vehicles 命名空间中有类
  • 文件夹 ClothingMyCompany.Project.Section.Clothing 命名空间中有类
  • 等等
  • 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

  • 文件夹 BusinessObjectsMyCompany.Project.Section 命名空间中有类
  • 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?

推荐答案

另外,请注意,如果您使用内置模板将类添加到文件夹,默认情况下会将其放在反映文件夹层次结构的命名空间中.

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.

我们遵循的规则是:

  • 项目/程序集名称与根命名空间相同,除了 .dll 结尾
  • 上述规则的唯一例外是项目以 .Core 结尾,.Core 被剥离
  • 文件夹等于命名空间
  • 每个文件一种类型(类、结构、枚举、委托等)可以轻松找到正确的文件

这篇关于解决方案中的文件夹是否应该与命名空间匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆