我有一些被DebuggerDisplayAttribute修饰的类。
我想能够在单元测试中添加跟踪语句,以显示这些类的实例。
.NET Framework中是否存在一种方法,可以显示使用DebuggerDisplayAttribute格式化的对象(如果未定义DebuggerDisplayAttribute,则返回使用.ToString())?
编辑:
为了澄清,我希望Framework中可能会有内置的东西。我知道我可以从DebuggerDisplayAttribute获取Value属性,但我需要使用由DebuggerDisplayAttribute.Value表示的格式字符串来格式化我的实例。
如果我自己编写,我预计将创建以下类型的扩展方法:
我想能够在单元测试中添加跟踪语句,以显示这些类的实例。
.NET Framework中是否存在一种方法,可以显示使用DebuggerDisplayAttribute格式化的对象(如果未定义DebuggerDisplayAttribute,则返回使用.ToString())?
编辑:
为了澄清,我希望Framework中可能会有内置的东西。我知道我可以从DebuggerDisplayAttribute获取Value属性,但我需要使用由DebuggerDisplayAttribute.Value表示的格式字符串来格式化我的实例。
如果我自己编写,我预计将创建以下类型的扩展方法:
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);
}