Anders G. Nordby

Senior Systems Consultant at Making Waves AS

Using DebuggerDisplayAttribute for easier debugging with PageTypeBuilder

I’m in the starting phase of a new project, and as always there are a few tricks to bring with me from my previous project… When developing with PageTypeBuilder, a good practice is to create an abstract class BasePage, inheriting from TypedPageData, and let all page types in my solution inherit from BasePage. This lets me add certain features to all the page types in my solution, and one of the first tricks is this little thing:

using System.Diagnostics;
using PageTypeBuilder;

namespace MakingWaves.MyNewProjectButIAmNotDisclosingTheCustomerNameHere.Model
{
    [DebuggerDisplay("PageType: {MyPageType}, PageName: {PageName}")]
    public abstract class BasePage : TypedPageData
    {
        public string MyPageType
        {
            get
            {
                // GetType() returns something like the following: "Castle.Proxies.PageTypeNameProxy"
                return GetType().ToString().Replace("Castle.Proxies.", string.Empty).Replace("Proxy", string.Empty);
            }
        }
    }
}

The DebuggerDisplayAttribute is a standard .Net feature that I know many of my fellow developers are unaware of. The DebuggerDisplayAttribute lets you format what is shown in the debugger, and you can include any public property (simply by matching on the name). Using this wisely makes all the difference when you’re debugging. When debugging an EPiServer solution, you’ll often come across a list of pages, and the trick above turns this

into this

…and I’m sure you’ll agree that this simple change makes debugging a site much easier!

About these ads

One Response to Using DebuggerDisplayAttribute for easier debugging with PageTypeBuilder

  1. Per Bjurström 2012-05-16 at 13:40

    Agree, very useful, we have done a few of these out-of-the-box in CMS vNext.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: