简体   繁体   English

在Visual Studio监视窗口中隐藏空成员

[英]Hide null members in Visual Studio watch window

How can I hide null members in watch screen? 如何在监视屏幕中隐藏空成员? I don't need that. 我不需要那个

Below is an screenshot: 以下是屏幕截图:

在此处输入图片说明

It doesn't work that way. 那样行不通。 The inspector is there for you to see all available members . 检查员在那里,您可以查看所有可用成员 The visibility of the members never has anything to do with the value of the member, null or otherwise. 成员的可见性从不与成员的有关,无论是null还是其他。 Conceivably you might be able to write a plugin that replaces the inspector in its entirety, to do what you want, but that would be a lot of work. 可以想象,您可以编写一个插件来完全替换检查器,以执行您想要的操作,但这将需要大量工作。

You can override the ToString on the class to display something that's useful to you. 您可以在类上重写ToString以显示对您有用的内容。 If you don't want to that your best bet might be to use the DebuggerDisplayAttribute attribute to create a DebuggerToString that can be used in the debugger. 如果您不希望这样做,最好的选择是使用DebuggerDisplayAttribute属性创建可在调试器中使用的DebuggerDisplayAttribute Have a look at this (MSDN) Enhancing Debugging with the Debugger Display Attributes or (blog) Why override ToString()? 看看这个(MSDN)使用调试器显示属性增强调试(blog)为什么要覆盖ToString()? Use DebuggerDisplayAttribute instead 改用DebuggerDisplayAttribute

You would do this at the class level on your GDicStruct rather than on the properties. 您可以在GDicStruct的类级别而不是属性上执行此操作。

So you could add 所以你可以添加

[DebuggerDisplayAttribute("{DebuggerToString}")]
public struct GDicStruct
{
    public string DebuggerToString()
    {
        //logic to create debugger string
    }
}

but you have to ask if it's worth the effort. 但您必须询问是否值得付出努力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM