[英]Show DebuggerDisplay in PropertyGrid C#
我想知道是否可以让调试器显示为PropertyGrid中类的文本?
我似乎在任何地方都找不到这个答案。
这是我所拥有的一个例子。
[DebuggerDisplay("FPS = {FPS}")]
[TypeConverter(typeof(ExpandableObjectConverter))]
public class DebugModule : Module
{
public int FPS {get; set;}
}
该模块位于Engine类中,因此当我设置propertyGrid.SelectedObject = engineInstance时,我希望在属性网格中看到
发动机+调试模块| “ FPS = 60”FPS | 60
怎么样,它在调试器和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);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.