[英]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.