views:

380

answers:

1

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?

+12  A: 

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="Program.cs" />
<Compile Include="Program.Foo.cs">
  <DependentUpon>Program.cs</DependentUpon>
</Compile>

appears as:

  • Program.cs
    • Program.Foo.cs
Marc Gravell
Didn't realise the DependentUpon worked on any files...
thecoop
The DependentUpon suggestion is really cool and works great. Thanks for noting. If I'm reading correctly, you don't simply use a standard suffix like "Custom." Your suffix always expresses the intent of the partial class file's functionality. Also, is there a reason why you use the . separation opposed to casing? Does the . provide anything more than improved readability? Thanks.
Ben Griswold
Correct - the file name indicates the intent of the code in *that portion*. So if I am implementing an exotic interface (and keeping the code separate), it might be `SomeType.ICustomTypeDescriptor.cs`. The `.` (IMO) separates the two things: the actual type (`SomeType`) and the intent `ICustomTypeDescriptor` - both are already fully cased; besides, it matches neatly with things like `SomeForm.Designer.cs` ;-p
Marc Gravell
Perfect. Thanks for the additional insight. If I could do more than up vote your answer and mark is as correct I would.
Ben Griswold
Does the nesting of the file in the Solution Explorer work if the dependent file is a 'linked' file?
Luke Baulch