Partial Class - Visual Studio 2008

Is it possible to create partial classes that are grouped in Solution Explorer, for example, VS does this with code behind the classes (for example, Default.aspx and Default.aspx.cs).

I would like to create MyClass.cs and MyClass.partial.cs, and they should not be displayed as two separate files in the solution explorer.

+4
source share
3 answers

I have not seen a way to do this in Visual Studio itself, but you can do this by editing the .csproj file. You need to find the place where the file you want to display under another file is in the proj file and add an element with the contents set to the name of the file you want to depend on.

Example:

<Compile Include="MyFile.g.cs"> <DependentUpon>MyFile.cs</DependentUpon> </Compile> 
+10
source

if you name the 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 other than managing the generated code. If you find yourself going down this route because there is too much code to support in one file, you should reconsider why there is so much code and break it into smaller classes along the lines that you are going to break anyway (I'm not saying that this is your case, but this is just advice).

+5
source

Not that I knew. As a rule, the goal is to support the generated code (i.e. you do not support it), so for this purpose, paste everything you need into a separate folder.

0
source

All Articles