有什么方法可以让 Visual Studio 调试器显示 F# seq
的内容表达?
Visual Studio 知道 IEnumerable<T>
对象并在监 window 口内为您提供结果 View 。如果您在监 window 口中查看其中一个,您会得到一堆私有(private)字段。
一些潜在的替代方案:
Seq.toArray
从调试器内部。我找不到从即时窗口调用它的正确语法。 编辑:进一步调查显示 F# 的
seq
对象实现 IEnumerable<T>
很好——它们就这样出现在监 window 口中——但由于某种原因,结果 View 没有出现。但是,F#
seq
对象似乎不是普通的 IEnumerables;相反,它们看起来是来自 Seq
中的函数的闭包。模块。 (F# seq
对象看起来是使用 { new IEnumerable with ... }
创建的实例。)
最佳答案
一种方法是使用 Results
在 Visual Studio 2008 中添加的 View 节点。如果将 System.Core.dll 加载到进程中,则任何实现 IEnumerable<T>
的类型展开时将获得一个名为 Results
的额外节点.展开该节点将枚举 IEnumerable<T>
并显示结果。
F# 类型 seq
只是 IEnumerable<T>
的别名所以它得到了同样的好处。
默认情况下,您在 F# 中看不到这一点,因为它不使用 System.Core 中的任何类型。但是您可以使用以下行强制此 DLL 进入进程。
// Force System.Core into the process
let x = typeof<System.Linq.Enumerable>
关于visual-studio - 在监 window 口中显示序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3512266/