VS.NET and Code Regions

I'm currently working on a project where almost every function has its own region. At first I found this convention onerous, but as I used it, I saw why it was necessary. The default Visual Studio .NET outlining support leaves a lot to be desired. Take your typical commented Page_Load method:

/// <summary>
/// This method is called when the Page's Load event has been fired.
/// </summary>
/// <param name="sender">The <see cref="object"/> that fired the event.</param>
/// <param name="e">The <see cref="EventArgs"/> of the event.</param>
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
// do stuff
}
}

That function will outline in two blocks: one for the XML comments, and another for the actual code itself:

Page_Load method using default outlining

It's aggravating that there is no built in support for outlining the entire function and the comments. Hence, the need for a simple region around the comments and the function, which provides the outlining support you might expect in the first place:

Page_Load method using custom region

I just checked, and VS.NET 2005 (aka Whidbey) has this same bad behavior. What a bummer. I am working on a macro that Region-izes all the functions in a file, but in the meantime you might want to check out the Documentator macros on CodeProject. They combine commenting and regionizing into one function, which isn't always what I want, but it's close enough to start.

Related posts

I Fight For The Users

I Fight For The Users

If you haven’t been able to keep up with my blistering pace of one blog post per year, I don’t blame you. There’s a lot going on right now. It’s a busy time. But let’s pause and take a moment to celebrate that Elon Musk

By Jeff Atwood ·
Comments
Updating The Single Most Influential Book of the BASIC Era

Updating The Single Most Influential Book of the BASIC Era

In a way, these two books are responsible for my entire professional career. With early computers, you didn’t boot up to a fancy schmancy desktop, or a screen full of apps you could easily poke and prod with your finger. No, those computers booted up to the command line.

By Jeff Atwood ·
Comments
To Serve Man, with Software

To Serve Man, with Software

I didn’t choose to be a programmer. Somehow, it seemed, the computers chose me. For a long time, that was fine, that was enough; that was all I needed. But along the way I never felt that being a programmer was this unambiguously great-for-everyone career field with zero downsides.

By Jeff Atwood ·
Comments
The Raspberry Pi Has Revolutionized Emulation

The Raspberry Pi Has Revolutionized Emulation

very geek goes through a phase where they discover emulation. It’s practically a rite of passage. I think I spent most of my childhood – and a large part of my life as a young adult – desperately wishing I was in a video game arcade. When I finally obtained my

By Jeff Atwood ·
Comments

Recent Posts

Let's Talk About The American Dream

Let's Talk About The American Dream

A few months ago I wrote about what it means to stay gold — to hold on to the best parts of ourselves, our communities, and the American Dream itself. But staying gold isn’t passive. It takes work. It takes action. It takes hard conversations that ask us to confront

By Jeff Atwood ·
Comments
Stay Gold, America

Stay Gold, America

We are at an unprecedented point in American history, and I'm concerned we may lose sight of the American Dream.

By Jeff Atwood ·
Comments
The Great Filter Comes For Us All

The Great Filter Comes For Us All

With a 13 billion year head start on evolution, why haven’t any other forms of life in the universe contacted us by now? (Arrival is a fantastic movie. Watch it, but don’t stop there – read the Story of Your Life novella it was based on for so much

By Jeff Atwood ·
Comments
I Fight For The Users

I Fight For The Users

If you haven’t been able to keep up with my blistering pace of one blog post per year, I don’t blame you. There’s a lot going on right now. It’s a busy time. But let’s pause and take a moment to celebrate that Elon Musk

By Jeff Atwood ·
Comments