gpt4 book ai didi

c# - 如何调试 Lazy

转载 作者:太空狗 更新时间:2023-10-30 01:17:19 24 4
gpt4 key购买 nike

我有一个 Lazy<T>用 lambda 初始化。调试时如何查看初始化 lambda 的主体?我希望有类似 DebugView 的东西的 Expression类,但我没有发现类似的东西。

最佳答案

因为 Lazy<T>接受代表,没有Expression类涉及。您的 lambda 像项目中的任何其他代码一样编译,并且在调试期间没有该代码的预览。

Lambda 表达式可以编译成 IL 或转换成表达式树。发生哪一个取决于上下文。如果您的参数声明为委托(delegate),将生成常规 IL 代码。如果是 Expression<TFunc>您将获得可以预览的表达式树。

很好explained on MSDN , 基于 Where方法,它有两个版本:Enumerable.Where这需要 Func<T, bool>Queryable.Where这需要 Expression<Func<T, bool>> .

When you use method-based syntax to call the Where method in the Enumerable class (as you do in LINQ to Objects and LINQ to XML) the parameter is a delegate type System.Func<T, TResult>. A lambda expression is the most convenient way to create that delegate. When you call the same method in, for example, the System.Linq.Queryable class (as you do in LINQ to SQL) then the parameter type is an System.Linq.Expressions.Expression<Func> where Func is any of the Func delegates with up to sixteen input parameters. Again, a lambda expression is just a very concise way to construct that expression tree. The lambdas allow the Where calls to look similar although in fact the type of object created from the lambda is different.

关于c# - 如何调试 Lazy<T>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32237202/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com