Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
    {
        SearchForMogwai,
        MogwaiFound,
    }
}

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

1 Answer 1

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">
  <DependentUpon>GremlinsProvider.cs</DependentUpon>
</Compile>

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.