Prior to v2 you would use the ToString method. When hovering
over an instance name in the VS debugger it will call the ToString
method to get the text to display in the tooltip. The problem with this approach
is that many controls also use this same method when converting an arbitrary value
to a string (such as in a list box).
class Test
{
public int Id { get { return 1234; } }
public string Name { get { return
"Michael"; } }
public override string ToString ( )
{ return String.Format("{0} [{1}]",
Name, Id); }
}
In v2 you should instead use the DebuggerDisplayAttribute attribute.
This attribute allows you to display useful information about the instance without
requiring the user to drill down into the properties or fields.
[DebuggerDisplay("{Name} [{Id}]")]
class Test
{
public int Id { get { return 1234; } }
public string Name { get { return
"Michael"; } }
}
The downside to this is that the debugger will use the ToString
method if it is defined over the attribute.