"partial" - making a part of a class dependant on the main in thesolution explorer

  • Thread starter Thread starter Benny Raymond
  • Start date Start date
B

Benny Raymond

I was trying to break some of my sections of code up into seperate files
using the new "partial" type definition and coudln't figure out how to
make the new files appear under the main file...

The only thing I could figure out to do was to open the .csproj file in
my text editor and change it so that it read "depends on"


Is there a way in the VS gui to do this?
 
Benny,

No, there is not. If you want a file to be dependent on another, you
have to have a specific designer for it, I believe. Otherwise, it just
shows up as another file.

What I usually do is have the file named in two parts. The first part
is the class name, the second part being what the partial implementation is
doing, and then the extension. Something like this:

MyClass.CodeThatDoesOneThing.cs
MyClass.CodeThatDoesOtherThings.cs

This way, they are grouped together when looking at them in solution
explorer.

Hope this helps.
 
Nicholas, I noticed that you can open the .csproj in a text editor and
add a line to where you want files to appear under other files. Here's
an example:

<Compile Include="frmMain.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="frmMain.Designer.cs">
<DependentUpon>frmMain.cs</DependentUpon>
</Compile>
<Compile Include="frmMain.Events.frmMain.cs">
<DependentUpon>frmMain.cs</DependentUpon>
<SubType>Form</SubType>
</Compile>


the "SubType>Form" gets added automatically - kinda dumb if you ask me.


Anyway, hopefully they will make this part of the gui in the future - I
don't like opening the .csproj file in a text editor.

~Benny
 
I don't believe this was the intended use. In fact, I would say this is
probably bad practice.
 
Hi,

I agree with you, using Nicholas's suggestion is the best approach, IMO

It's not a good idea hand touching the files generated for internal uses of
VS


cheers,
 
But why then would it be there, why would VS create it's own partial
files that show up in a tree under the file they are bound to but not
allow you to do this yourself?

Adding the XML line to the .csproj moves the file where it should be and
doesn't appear to affect the application at all. This line in XML looks
like it's strictly for display purposes.

Regardless, the fact that when you create a form and it puts the
designer code in a file under the form's main .cs file and the fact that
there is seemingly no way (without a little bit of hackary) to do this
yourself seems like a bug in the VS 2005 gui.

~Benny
 
Back
Top