表达式树不能包含使用可选参数的调用或调用 [英] An expression tree may not contain a call or invocation that uses optional arguments
本文介绍了表达式树不能包含使用可选参数的调用或调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
表达式树不能包含使用可选参数
An expression tree may not contain a call or invocation that uses optional arguments
return this.RedirectToAction<MerchantController>(x => x.Edit(merchantId));
edit 有第二个可为空的参数.
Where edit had a second, nullable argument.
这是为什么?
推荐答案
底层表达式树 API 不支持可选参数.
对于 IL 编译的代码,C# 编译器在编译时插入默认值(硬编码),因为 CLR 不支持在未显式提供参数时调用带有可选参数的方法.
For IL-compiled code the C# compiler inserts the default values at compile time (hard-coded), because the CLR does not support calling methods with optional arguments either when the arguments are not provided explicitly.
这篇关于表达式树不能包含使用可选参数的调用或调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文