Nesting Partial Classes in the Solution Explorer
If you have started using the new Partial Classes feature of .net 2, you will no doubt have wondered why your partial class is not displayed nested beneath the main class.
If you create a winforms project, you will notice that the form1.designer.cs file is displayed beneath the form1.cs file, so why can't your custom partial class be displayed like this too?
Fortunately it can, but unfortunately there doesn't seem to be a way to do it through the Visual Studio 2005 IDE.
To get the class to display correctly, open up your project file in a text editor. Scroll down to the <itemgroup> node containing your class within a <compile include="[class file]"> node.
If you are looking at a winforms project, you will notice that any form.designer.cs classes contains a <dependentupon> node containing the name of the master file.
Add <dependentupon>[master class file]</dependentupon> as a subnode of the <compile> node of your partial class.
When you refresh the solution explorer, your class should appear nested beneath it.
If you create a winforms project, you will notice that the form1.designer.cs file is displayed beneath the form1.cs file, so why can't your custom partial class be displayed like this too?
Fortunately it can, but unfortunately there doesn't seem to be a way to do it through the Visual Studio 2005 IDE.
To get the class to display correctly, open up your project file in a text editor. Scroll down to the <itemgroup> node containing your class within a <compile include="[class file]"> node.
If you are looking at a winforms project, you will notice that any form.designer.cs classes contains a <dependentupon> node containing the name of the master file.
Add <dependentupon>[master class file]</dependentupon> as a subnode of the <compile> node of your partial class.
When you refresh the solution explorer, your class should appear nested beneath it.
2 Comments:
Oh man you're a life saver! I've been wondering how to add master classes to a sub-node in a winforms project.
I'm glad you found it helful scroop. Today I found this other article I think might interest you.
Post a Comment
<< Home