How about this, which displays the same text in the debugger and PropertyGrid
:
[DebuggerDisplay("{.}")]
[TypeConverter(typeof(ExpandableObjectConverter))]
public class DebugModule : Module
{
public int FPS { get; set; }
public override string ToString() { return "FPS = " + FPS; }
}
Or if you need to use ToString
for something else:
[DebuggerDisplay("{DebugDisplayText}")]
[TypeConverter(typeof(DebugModuleConverter))]
public class DebugModule : Module
{
public int FPS { get; set; }
private string DebugDisplayText { get { return "FPS = " + FPS; } }
public class DebugModuleConverter : ExpandableObjectConverter {
public override object ConvertTo(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value,
Type destinationType) {
if(destinationType == typeof(string)) {
return ((DebugModule) value).DebugDisplayText;
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}
Marc Gravell
2010-07-20 10:37:02