I have a number of classes that are decorated with DebuggerDisplayAttribute.
I want to be able to add trace statements to Unit Tests that will display instances of these classes.
Does there exist a method in the .NET Framework that will display an object formatted using DebuggerDisplayAttribute (or fall back to using .ToString() if no DebuggerDisplayAttribute is defined)?
EDIT
To clarify, I was hoping there might be something built into the Framework. I know I can get the Value property from DebuggerDisplayAttribute, but I then need to format my instance using the format string represented by DebuggerDisplayAttribute.Value.
If I roll my own, I'd envisage an extension method along the following lines:
public string FormatDebugDisplay(this object value)
{
DebugDisplayAttribute attribute = ... get the attribute for value ...
if (attribute = null) return value.ToString();
string formatString = attribute.Value;
??? How do I format value using formatString ???
return SomeFormatMethod(formatString, value);
}