簡體   English   中英

在PropertyGrid C#中顯示DebuggerDisplay

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM