Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming Conventions For Partial Class Files

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?

like image 687
Ben Griswold Avatar asked Sep 25 '09 17:09

Ben Griswold


People also ask

Can partial class have different names in different files?

The source file name for each part of the partial class can be different, but each partial class's name must be the same. The name of all parts of a partial class should be the same. All parts of a partial class should be in the same assembly.

What is the best naming convention for files?

File naming best practices:Avoid special characters or spaces in a file name. Use capitals and underscores instead of periods or spaces or slashes. Use date format ISO 8601: YYYYMMDD.

Can partial class have same method name?

It doesn't compile as you can't have two methods with the same name in one class.


1 Answers

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
like image 164
Marc Gravell Avatar answered Sep 25 '22 13:09

Marc Gravell