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.

Read more

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

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

By Jeff Atwood · · Comments

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

By Jeff Atwood · · Comments

The 2030 Self-Driving Car Bet

It's my honor to announce that John Carmack and I have initiated a friendly bet of $10,000* to the 501(c)(3) charity of the winner’s choice: By January 1st, 2030, completely autonomous self-driving cars meeting SAE J3016 level 5 will be commercially available for passenger

By Jeff Atwood · · Comments