为什么不能Visual Studio调试器枚举BitArray并告诉我结果如何? [英] Why won't Visual Studio Debugger enumerate a BitArray and show me the results?

查看:156
本文介绍了为什么不能Visual Studio调试器枚举BitArray并告诉我结果如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关以下行的C#代码:

For the following line of C# code:

BitArray bitty = new BitArray(new[] {false, false, true, false});

如果我在监视窗口评价片断,我看不到集合的成员。如果我评价片断,成果,这是应该列举IEnumerable和显示结果,我得到的消息只可枚举类型可以有结果视图,即使BitArray IS一个IEnumerable

If I evaluate "bitty" in the Watch window, I don't see the members of the collection. If I evaluate "bitty, results", which is supposed to enumerate the IEnumerable and show the results, I get the message "Only Enumerable types can have Results View", even though a BitArray IS an IEnumerable.

为什么调试器做到这一点

CLARIFICAITON:?我要问什么是VS调试器内部发生表达式求值,而不是询问如何在调试器。

CLARIFICAITON: I'm asking what is happening inside the VS Debugger Expression Evaluator, NOT asking how to view a BitArray in the debugger..

推荐答案

结果只能查看查看BitArray适用于符合集合以下条件:

The results view only works for collections which meet the following conditions:


  1. 实施的IEnumerable< T> 的IEnumerable (VB.Net只适用于的IEnumerable< T>

  2. 不会实施的IList 的IList< T> 的ICollection 的ICollection< T> (C#限制只)

  3. 不可以有一个 DebuggerTypeProxy 属性

  4. System.Core.dll被加载到调试进程

  1. Implement IEnumerable<T> or IEnumerable (VB.Net only works for IEnumerable<T>)
  2. Do not implement IList, IList<T>, ICollection or ICollection<T> (C# restriction only)
  3. Do not have a DebuggerTypeProxy attribute
  4. System.Core.dll is loaded in the debugee process

在这种情况下, BitArray 同时实现了的IEnumerable 的ICollection 。后者从结果视图中使用它不够格。

In this case BitArray implements both IEnumerable and ICollection. The latter disqualifies it from being used with the results view.

要解决的一个方法是使用铸造扩展方法。这就产生了一个的IEnumerable< T>从中你可以使用结果视图

One way to work around this is to use the Cast extension method. This produces an IEnumerable<T> value from which you can use the results view

bitty.Cast<bool>(), results

原因#2是一个组合因素:

The reason for #2 is a combination of factors:


  • 的结果认为最初发明解决一个非常具体的问题:C#迭代器的调试经验(通过扩展LINQ查询)是穷人。根本就查看的内容没有什么好办法了IEnumerable< T>

  • 的结果看法是不的免费的和确实有非常具体的风险。特别是将整个集合热切和同步加载到内存中。这可能会导致问题,通过数据库查询,非常大的或无限集合

  • 所有已知的IList /<支持收藏; T> 的ICollection< T> 键入已经有一个让你查看内容<方法/ li>
  • The Results view was originally invented to solve a very specific problem: the debugging experience of C# iterators (and by extension LINQ queries) was poor. There was simply no good way to view the contents of the IEnumerable<T>.
  • The Results view is not free and does have very specific risks. In particular it will eagerly and synchronously load the entire collection into memory. This can cause issues with collections backed by database queries, extremely large or infinite collections
  • Every known IList/<T> and ICollection<T> type already have a method that let you view the contents

因此,C#团队决定把风险降到最低,而不是的IEnumerable<增加; T> 来,他们认为已经很好显示类型。 VB.Net选择了另一个方向,并显示它的任何的IEnumerable< T>

Hence the C# team decided to minimize risk and not add IEnumerable<T> to types which they felt already displayed well. VB.Net chose the other direction and will display it for any IEnumerable<T>.

您可以理所当然地问怎么两队可以看同样的数据,并做出不同的决定。它归结为视角,当然时间。该VB.Net队上提供了极大的LINQ调试经验非常热衷。 VB.Net有提供了丰富的调试+ ENC的经验,因此是更习惯于/愿意冒这种类型的风险对,另外不得不测试它的带宽很长的历史。 C#只是更厌恶风险,非常紧的时间表和务实决定反对。

You might rightfully ask how two teams could look at the same data and make different decisions. It comes down to perspective and of course time. The VB.Net team was very keen on providing a great LINQ debugging experience. VB.Net has a long history of providing a rich debugging + ENC experience and hence was more accustomed / willing to take this type of risk on and additionally had the bandwidth to test it. C# was simply more risk averse, very tight on the schedule and pragmatically decided against it.

请注意:我前面约的IEnumerable混乱不被支持的,因为这实际上在VB表达式求值的情况。 C#的表达式求值确实支持的IEnumerable 虽然和按上述规则。

Note: My earlier confusion about IEnumerable not being supported is because that's actually the case in the VB expression evaluator. The C# expression evaluator does support IEnumerable though and by the above rules.

这篇关于为什么不能Visual Studio调试器枚举BitArray并告诉我结果如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆