Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attribute that displays property value in Visual Studio

I believe I saw somewhere an attribute that, when applied to a class, would show the value of a property in intellisense. I'm not talking about XML comments. It looked something like this:

[SomeAttribute("Name = '{0}', Age = '{1}'", Name, Age)]
MyClass

Anyone know which Attribute I'm talking about?

like image 422
adam0101 Avatar asked Feb 23 '11 15:02

adam0101


1 Answers

It doesn’t make sense to “show a value in IntelliSense”, but I guess you mean in the debugger. In that case, the attribute you’re looking for is DebuggerDisplayAttribute:

[DebuggerDisplay("Name = '{Name}', Age = '{Age}'")]
public class XYZ
{
    public string Name;
    public int Age;
}

Of course, you can also override the ToString() method instead. In the absense of a DebuggerDisplayAttribute, the debugger uses ToString(). You should use DebuggerDisplayAttribute only if you really need the implementation of ToString() to be different (and insufficient for debugging).

like image 68
Timwi Avatar answered Sep 24 '22 13:09

Timwi