Naming Conventions For Partial Class Files

I use . separation - for example EmployeeController.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:

<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>

appears as:

  • Subfolder
    • Program.cs
      • Program.Foo.cs

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:

<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>

I hope this helps someone :)