Tuesday, August 7, 2012

Grouping Partial Classes in Visual Studio Solution Explorer

Much has already been said on how useful .Net's partial classes can be. But not much on how to organize them well in Visual Studio's Solution Explorer. Given the below web application project:

Figure 1: New Partial Class File Added

The aspx page WebForm1.aspx has the default code-behind file and the designer file. For example, let's add a partial class to WebForm1 to handle validations for the page. By default, this new class file is not grouped with WebForm1.aspx like the others. Wouldn't it make sense to group this new partial class with the existing group?

The extension VSCommands 2010 has a handy command to join the new class into the existing group. It is as simple as selecting the parent class (in this case, the aspx file) and the new partial class (the aspx.validations.cs file), then clicking on Group Items.

Figure 2: Using VSCommands to Group Items

From here, a popup window will appear verifying which one should be the parent of the selected files, as shown below for Visual Studio 2010:

Figure 3: VSCommands Root Item Selector

We'll keep the aspx file as the parent. With this, we now have the following structure in the Solution Explorer:

Figure 4: New Partial Class Added to Group

The new partial class aspx.validations.cs is now a member of the WebForm1 class group! This also works for Windows Forms projects, and Visual Basic projects as well.

It should be noted that this makes sense for partial classes, but we are not limited to partial classes when grouping them in Solution Explorer! We can join any other class into the group if we wanted. Say, if we have a dedicated helper class for WebForm1 and it is not a partial class, we can still add it to the group. And we can select more than two files at the same time to initiate the item grouping. There will just be more files listed in VSCommands' root item selector in figure 3. It is even possible to attach a class to another sub-item in an existing group, creating deeper levels in the solution tree.

We actually don't need VSCommands to take advantage of this. The grouping is configured in the project file, as shown in the below snippet:

Figure 6: Project File Configurations
In figure 5, the new partial class aspx.validations.cs is given a new node value denoting which existing object it should be attached to. The default classes already has this node connected to WebForm1.aspx, so it is grouped by default. VSCommands just makes things easier and safer to do.


  1. Hey , Kevin

    Your blog posted on '' Studio Solution Explorer '' which , I seen your blog . I have learned more tips by this your blog many ways . Awesome consultant of Studio Solution Explorer program software . Really , I saluted your blog . Some 100 % free Hard drive data is finish of ads which are intentionally quite obstructive and frustrating. The developer earns a bit of cash from the ads, and states that if you register the program you can create the ads go away. Signing up often expenses just a few money, and if you like the program it may be well value the price.

    Thanks for sharing .

  2. We offer a couple of the classes beneath at our wellness excursion too which gives assortment in the every day line up. In any case, in case you're searching for something else and feeling like you need an adjustment of your ordinary line up, look at these classes. Best Assignment Help Online

  3. These classes are the best and useful for students because through these, they can improve their studies and get high grades. They can also make their future bright and spend a successful life. Coursework writing services.


  4. A research paper help service is basically an academic paper writing help company or agency that helps students write academic papers. Such companies provide reference material. Several research writing services have come into existence over the past few decades. But students trust us the most, because of our unique quality timely delivery and rapid change.

  5. If you are still in a dilemma, you could ask your teacher for some guidance, or you can take Assignment help from different assignment writing service providers. you can find many online assignment experts, who are all set to help you with your assignment. The proper outline followed by them will give you an idea of how to make your assignment look more presentable and attractive. Many people are depressed about the problems of statistics assignment help. Well, don’t worry about that because we are providing this service at a very reasonable price.

  6. Classes Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained!

  7. Transfer It proved to be Very helpful to me and I am sure to all the commentators here!

  8. How to get to JW Marriott Hotel Casino & Spa by Bus - Jtm Hub
    Find 포항 출장안마 the best ways to get from JW Marriott 나주 출장샵 Hotel 강릉 출장안마 Casino & Spa by 제천 출장안마 Bus to JW Marriott Hotel 부산광역 출장마사지 Casino & Spa by Bus.

  9. The definition of an explorer is a person who travels and investigates little known places. An example of email validation an explorer is Sir Ernest Shackleton, the Antarctica explorer.

  10. This certainly shows of their portfolio, with the visual belongings stuffed with vibrant colours. Step into our High Limit Room, where you retreat to an intimate setting that features premium leather furniture, a devoted cashier cage and, of course, high denomination slot machines. But then what happens after 4-coin flips, on the fifth flip, what are the odds of getting heads? The odds of chances of an occasion 1xbet occurring randomly are utterly unbiased of the outcomes of earlier occasions.