部分类文件的命名约定
我正在生成大部分 ASP.NET MVC 脚手架代码。所有生成的文件都是使用标准命名约定的部分类。例如,我的员工控制器文件名为 EmployeeController.cs。如果我希望使用自定义的非生成逻辑扩展 EmployeeController,我将创建第二个名为 EmployeeControllerCustom.cs 的部分类文件。我将自定义逻辑和生成逻辑分离到两个不同的文件中,以便下次生成 EmployeeController 时,我的自定义更改不会被覆盖。在文件名中添加“自定义”后缀对我来说似乎是合理的,但是是否有我应该遵循的更成熟的部分类文件命名约定?
I'm generating the bulk of my ASP.NET MVC scaffolding code. All generated files are partial classes which use standard naming conventions. For example, my employee controller file is named EmployeeController.cs. If I wish to extend the EmployeeController with custom, non-generated logic, I create a second partial class file named EmployeeControllerCustom.cs. I separate the custom and generated logic into two different files so the next time I generate the EmployeeController my custom changes aren't overwritten. Adding the "Custom" suffix to the file name seems reasonable to me, but is there a more established partial class file naming convention which I should be following?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用
.
分隔 - 例如EmployeeController.SomeSpecialBehaviour.cs
。我还通过“dependentUpon”或 csproj 中的任何内容将其链接到项目树中,以便它整齐地嵌套在文件下(在解决方案资源管理器中)。不过,您必须手动(编辑 csproj)或使用插件来完成此操作;例如:显示为:
Program.cs
Program.Foo.cs
I use
.
separation - for exampleEmployeeController.SomeSpecialBehaviour.cs
. I also link it into the project tree via "dependentUpon" or whatever it is in the csproj, so that it nests under the file (in solution explorer) neatly. You have to do that by hand (edit the csproj) or with an addin, though; for example:appears as:
Program.cs
Program.Foo.cs
更新/免责声明:
2018 年,有人编辑了 Marc Gravell 的答案(上面接受的答案),在他的示例中包含一个子文件夹。如何处理有子文件夹的情况是这个答案的要点。
如果没有该免责声明,您可能不会理解为什么这个答案存在以及为什么它有如此多的选票。
为了添加 Marc Gravell 的答案,我遇到了子文件夹中的文件和 < code>DependentUpon 节点被忽略。缺点是在这种情况下我的 xml 必须是:
我希望这对某人有帮助:)
UPDATE / DISCLAIMER:
On 2018 someone edited Marc Gravell♦'s answer (the one accepted above) to include a subfolder in his example. And how to handle the case of having a subfolder is the main point of this answer.
Without that disclaimer you probably wouldn't understand why this answer exists and why it has so many votes.
To add to Marc Gravell♦'s answer, I had a situation with files in a subfolder and the
DependentUpon
node being ignored. The short of it is that in such a case it my xml had to be:I hope this helps someone :)