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?
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.
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.
It doesn't compile as you can't have two methods with the same name in one class.
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:
Program.cs
Program.Foo.cs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With