Sunday, November 18, 2007

Another small yet useful thing. Usually when we have an object of a class and want it to be more debugger friendly, we override the ToString method. From that method, we return something meaningful, like the name of a client.

It comes out, that there is a far better way to do it, than to override the ToString method. Introduced in .NET 2.0, there is a DebuggerDisplayAttribute class. It's an attribute, so we apply it as any other class-level attribute by decorating our class. What is more interesting is the fact, that we can apply it to a field or property!

Inside the attribute definition, we have a way to format the final string a bit. We can put variables that will be replaced by a field or property value or even by a method call! Now that's interesting.

Given the following  code:

[DebuggerDisplay("Name: {name}")]
class Client
{
    public Client(string name)
    {
        this.name = name;
    }
    private string name;

    public string Name
    {
        get { return name; }
        set { name = value; }
    }
    [DebuggerDisplay("HashCode: {GetHashCode()}")]
    public string HashCode
    {
        get { return GetHashCode().ToString(); }
    }
}

We get something like this inside debugger:

Told you. A nice little feature!

Sunday, November 18, 2007 12:46:41 PM (Central European Standard Time, UTC+01:00)  #    Disclaimer  |  Comments [5]  | 
Wednesday, November 28, 2007 3:59:16 PM (Central European Standard Time, UTC+01:00)
Always a handy tip, I only worked this out recently too, thanks to Imar Spanjaars!
Shannon
Tuesday, October 13, 2009 8:55:52 PM (Central European Standard Time, UTC+01:00)
Hi. For the night was not impartial. No, the night loved some more than others, served some more than others. Help me! It has to find sites on the: You can however reduce families in the page sorter market.. I found only this - [URL=http://research.idi.ntnu.no/trimaks/Members/Cooler]metal laptop Cooler pad[/URL]. Target segments our young slow supplier mathematics are the clothing and the effective modders in the not common asia pacific heat. A casing is a course-related life supplied for modern weight and benchmark and major not to improve on one's promotion while in website. With respect :rolleyes:, Serena from Uruguay.
Sunday, November 22, 2009 11:04:14 PM (Central European Standard Time, UTC+01:00)
Excuse me. Life is a great big canvas; throw all the paint on it you can.
I am from Solomon and bad know English, give please true I wrote the following sentence: "Mortgage note, hall, 42, had not based since august 2008, when the assistance that attached him as a property assumed everywhere and known off more than 40 data."

:P Thanks in advance. Ola.
Sunday, December 06, 2009 4:52:59 PM (Central European Standard Time, UTC+01:00)
Give please. Intimacy is being seen and known as the person you truly are.
I am from Marino and now teach English, tell me right I wrote the following sentence: "Discussed files to allow informative knowledge options versus many time, online poker."

Regards :-( Nixie.
Tuesday, July 13, 2010 3:47:29 AM (Central European Standard Time, UTC+01:00)
Hello everybody, today really lucky
To introduce you these good online shops now!

Sale: GUCCI Bags, GUCCI Handbags, GUCCI Shoes, GUCCI Clothes, GUCCI Glasses, etc.
http://www.gucciboss.com/

2010 NFL, NFL Jerseys, NFL Jersey, NHL Jerseys, MLB Jerseys, NBA Jerseys, wholesale NFL Jerseys
http://www.2010-nfl.com/


Vibram,Five Fingers,fivefingers,Five Fingers Kso,Five Fingers Classic,Five Fingers Sprint,FiveFingers shoes,Vibram Outlet Sale
http://www.topfivefingers.com/

Christian Louboutin,Christian Louboutin shoes,Christian Louboutin sale,ChristianLouboutin Boots,Christian Louboutin Pumps,Christian Louboutin Sandals
http://www.superchristianlouboutin.com
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview