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.
项目名称和命名空间:MyCompany.Project.Section.
Project Name and Namespace: MyCompany.Project.Section.
在这个项目中,有几个文件夹与命名空间部分匹配:
Within this project, there are several folders that match the namespace section:
- 文件夹
Vehicles在MyCompany.Project.Section.Vehicles命名空间中有类 - 文件夹
Clothing在MyCompany.Project.Section.Clothing命名空间中有类 - 等等
- Folder
Vehicleshas classes in theMyCompany.Project.Section.Vehiclesnamespace - Folder
Clothinghas classes in theMyCompany.Project.Section.Clothingnamespace - etc.
在同一个项目中,还有另一个恶意文件夹
Inside this same project, is another rogue folder
- 文件夹
BusinessObjects在MyCompany.Project.Section命名空间中有类
- Folder
BusinessObjectshas classes in theMyCompany.Project.Sectionnamespace
有一些类似的情况是为了组织方便"而制作文件夹.
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 被剥离
- 文件夹等于命名空间
- 每个文件一种类型(类、结构、枚举、委托等)可以轻松找到正确的文件
这篇关于解决方案中的文件夹是否应该与命名空间匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:解决方案中的文件夹是否应该与命名空间匹配?
基础教程推荐
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
