Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Visual Studio projects, I often use partial classes to extract specific and uniform data, such as database queries or trace IDs, from the code. Example:

public partial class GremlinsProvider
    public Mogwai GetAMogwai()
        TraceEvent(TraceEventType.Start, TraceId.SearchForMogwai,
            "Querying the database for a Mogwai.");
        var mogwai = new DataQuery(Queries.FindMogwai).ReadRow<Mogwai>();

        TraceEvent(TraceEventType.Stop, TraceId.MogwaiFound, "Found a Mogwai.");
        return mogwai;

public partial class GremlinsProvider
    private class Queries
        public const FindMogwai = @"
            select top 1
            from [Gremlins]
            where [IsAvailable] = 1 and [PetName] = N'Mogwai'";

public partial class GremlinsProvider
    private enum TraceId

In this case, I create three files:

  • GremlinsProvider.cs which contains the logic,
  • GremlinsProvider.Queries.cs which contains the constant strings with database queries,
  • GremlinsProvider.Trace.cs which contains the enumeration of trace IDs.

In Solution Explorer, I want those files to appear collapsed. For example GremlinsProvider.cs will expand to contain GremlinsProvider.Queries.cs and GremlinsProvider.Trace.cs as its children, just like Solution Explorer collapses designer or resources files in a Windows Forms project.

Is it possible to do it with existent solutions (i.e. without having to write my own extension), either by configuring Visual Studio 2010 or through an extension?

share|improve this question
up vote 2 down vote accepted

I have no idea what side-effects this may cause!

From what I can tell, the folding is taken from the DependentUpon setting in the .csproj file.

As an example, the entry for GremlinsProvider.Queries.cs should look like this:

<Compile Include="GremlinsProvider.Queries.cs">

This can be modified at any time during development (no need to create a new project).

If you're wondering whether this can be achieved easier through the IDE, it seems like the answers is Nope but there is an extension that promises to do this: VSCommands (the feature is called Group / Ungroup Items).

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .