The previous pages explain the concept of partial classes and show how to code them. But Microsoft uses one more trick with the partial classes generated by Visual Studio. One of the reasons for using them is to separate application logic from UI (user interface) code. In a large project, these two types of code might even be created by different teams. If they're in different files, they can be created and updated with a lot more flexibility. But Microsoft goes one more step and hides the partial code in Solution Explorer as well. Suppose we wanted to hide the methods and properties partial classes in this project? There's a way, but it's not obvious and Microsoft doesn't tell you how.
One of the reasons you don't see the use of partial classes recommended by Microsoft is that it's not really supported very well in Visual Studio yet. To hide the Partial.methods.vb and Partial.properties.vb classes that we just created, for example, requires a change in the vbproj file. This is an XML file that isn't even displayed in Solution Explorer. You can find it with Windows Explorer along with your other files. A vbproj file is shown in the illustration below.
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
The way we're going to do this is to add a "root" class that is completely empty (only the Class header and End Class statement are left) and make both of our partial classes dependent on it. So add another class named PartialClassRoot.vb and again change the internal name to PartialClass to match the first two. This time, I have not used the Partial keyword just to match the way Visual Studio does it.
Here's where a little knowledge of XML will come in very handy. Since this file will have to be updated manually, you have to get the XML syntax right. You can edit the file in any ASCII text editor - Notepad works just fine - or in an XML editor. It turns out that you have a great one in Visual Studio and that's what is shown in the illustration below. But you can't edit the vbproj file at the same time that you're editing the project it's in. So close the project and open only the vbproj file. You should see the file displayed in the edit window as shown in the illustration below.
(Note the Compile elements for each class. DependentUpon sub-elements must be added exactly as shown in the illustration below. This illustration was created in VB 2005 but it has been tested in VB 2008 as well.)
--------
Click Here to display the illustration
Click the Back button on your browser to return
--------
For many of us, it's probably enough to know that partial classes are there, just so we know what they are when we're trying to track down a bug in the future. For large and complex systems development, they could be a small miracle because they can help organize code in ways that would have been impossible before. (You can also have partial structures and partial interfaces!) But some people have concluded that Microsoft invented them just for internal reasons - to make their code generation work better. Author Paul Kimmel even went so far as to suggest that Microsoft actually created partial classes to lower their costs by making it easier to outsource development work around the world.
Maybe. It's the kind of thing they might do.

