这个怎么样,它在调试器中显示相同的文本并且PropertyGrid
:
[DebuggerDisplay("{.}")]
[TypeConverter(typeof(ExpandableObjectConverter))]
public class DebugModule : Module
{
public int FPS { get; set; }
public override string ToString() { return "FPS = " + FPS; }
}
或者,如果您需要ToString
用于其他用途:
[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);
}
}
}