views:

703

answers:

3

Is there a possibility to create partial classes that are grouped in the Solution Explorer like VS does it with code behind classes (eg. Default.aspx and Default.aspx.cs).

I would like to create MyClass.cs and MyClass.partial.cs and they should not be shown as 2 seperate files in the Solution explorer.

A: 

Not that I know of. Generally, the purpose is to support generated code (ie, you're not maintaining it), so for that purpose, putting it in a separate folder is all you would need.

jvenema
+6  A: 

I've not seen a way to do this within Visual Studio itself, but it is possible to do it by editing the .csproj file. You need to find the place where the file you want to show up under the other file is in the proj file and add a element with the content set to the name of the file you want to be dependent upon.

example:

<Compile Include="MyFile.g.cs">
    <DependentUpon>MyFile.cs</DependentUpon>
</Compile>
dustyburwell
+4  A: 

if you name you file MyClass.designer.cs, it does.

There are a few "magic names" that work (.xaml.cs is another one I think).

As an aside, I think partial classes should not be used for anything else than managing generated code. If you find yourself going down that route because there is too much code to maintain in one file, you should reconsider why there is so much code and break it into smaller classes along the lines you were going to break it down anyway (I'm not saying this is your case, but it's just a piece of advice).

Denis Troller
You hit the point. I got to work on a huge project with bad design and way to big "I do everything" classes. It cries for refactoring, but it will not be done for several (non technical) reasons. So I tried to make the nightmare a little less scarry.
chbu
I feel for you...Good luck anyway.
Denis Troller