本文介绍了用于任何ICollection和ICollection的调试器可视化< T>类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用网格创建表单来可视化任何集合( ICollection ICollection< T> )对象。 p>

之后,我创建了调试器可视化器类(继承自 Microsoft.VisualStudio.DebuggerVisualizers.DialogDebuggerVisualizer )。



可视化程序已安装(我在 System.Collections.ArrayList 类中尝试)。



但是,我有问题可以将可视化程序概括为任何 ICollection / ICollection 类型。



我指定的属性:

  [assembly:DebuggerVisualizer(typeof DebugerSide),typeof(VisualizerObjectSource),Target = typeof(System.Collections.Generic.ICollection),描述=Collection visualizer)] 
[assembly:DebuggerVisualizer(typeof(DebugerSide)),typeof(VisualizerObjectSource) ,Target = typeof(System.Collections.ICollection),Description =Collection visualizer)]

但Visual VS不提供可视化调试。



如果我指定了exactl类名,则可视化在VS中可用。有没有办法,如何执行我的意图或没有办法,如何实现?



谢谢!

解决方案

我认为你已经陷入与Visualizer架构相同的限制,如。


I created form with grid to visualize any collection (ICollection, ICollection<T>) object.

After that I created debugger visualizer class (inherits from Microsoft.VisualStudio.DebuggerVisualizers.DialogDebuggerVisualizer).

The visualizer is installed propertly (I tried it on System.Collections.ArrayList class).

But I have problem with generalize the visualizer to any ICollection/ICollection<T> type.

I specified attribute:

[assembly: DebuggerVisualizer( typeof( DebugerSide ), typeof( VisualizerObjectSource ), Target = typeof( System.Collections.Generic.ICollection<> ), Description = "Collection visualizer" )]
[assembly: DebuggerVisualizer( typeof( DebugerSide ), typeof( VisualizerObjectSource ), Target = typeof( System.Collections.ICollection ), Description = "Collection visualizer" )]

but the visualizer is not offered by VS in debug.

If I specify exactl class name, the visualizer is available in VS. Is there way, how to perform my intention or there is no way, how to achieve it?

Thanks!

解决方案

I think you've stumbled into the same limitation of the Visualizers architecture as outlined in this question.

The workaround is to create a Visualizer for System.WeakReference, and then to type in the Watch window "new WeakReference(myCollectionVariable)", and then you will be able to open your debug visualizer on the weakreference. Inside your debug visualizer you can use reflection to find out what exactly the type of your variable is, and do whatever you want with it.

See also this.

这篇关于用于任何ICollection和ICollection的调试器可视化&lt; T&gt;类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 00:36