-->

约定对局部类文件(Naming Conventions For Partial Class File

2019-07-19 16:31发布

我生成了大部分我的ASP.NET MVC脚手架代码。 所有生成的文件是使用标准的命名约定部分类。 例如,我的员工控制器文件名为EmployeeController.cs。 如果我希望向EmployeeController用定制的,非产生的逻辑延伸,我创建第二部分类文件名为EmployeeControllerCustom.cs。 我单独定制和生成的逻辑在两个不同的文件,所以下一次我产生EmployeeController我的自定义更改不会被覆盖。 添加“自定义”为后缀的文件名似乎是合理的给我,但有我应以下一个更成熟的部分类文件的命名约定?

Answer 1:

我使用. 分离-例如EmployeeController.SomeSpecialBehaviour.cs 。 我也通过“dependentUpon”或不管它是在的csproj,使之巢下的文件(在解决方案资源管理)整齐地将其链接到项目树。 你必须这样做手工(编辑的csproj),或通过插件,虽然; 例如:

<Compile Include="Subfolder/Program.cs" />
<Compile Include="Subfolder/Program.Foo.cs">
  <DependentUpon>Program.cs</DependentUpon> <!-- Note that I do not reference the subfolder here -->
</Compile>

表现为:

  • 子文件夹
    • Program.cs
      • Program.Foo.cs


Answer 2:

为了增加马克Gravell♦的回答,我有一个子文件夹和文件的情况DependentUpon节点被忽略。 它的短是,在这样的情况下,我的XML必须是:

<Compile Include="foo\bar.cs" />
<Compile Include="foo\bar.baz.cs">
    <DependentUpon>bar.cs</DependentUpon>  <!-- Note that I do not reference the subfolder here -->
</Compile>

我希望这可以帮助别人 :)



文章来源: Naming Conventions For Partial Class Files