如何调用泛型 lambda 表达式?
private void ExecuteCommand(Expression<Func<bool>> command)
{
bool success = command.Compile().Invoke();
}
private void Test()
{
ExecuteCommand(() => _gc.ChargeCancellation(""));
}
通过这段代码,我得到了一个 NullReferenceException。
private void ExecuteCommand(Expression<Func<bool>> command)
{
bool success = command.Compile().Invoke();
}
private void Test()
{
ExecuteCommand(() => _gc.ChargeCancellation(""));
}
With this code, I got a NullReferenceException.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
_gc
是否有可能为空?或者也许ChargeCancellation
本身正在抛出异常?否则应该可以正常工作。Is
_gc
null by any chance? Or perhapsChargeCancellation
itself is throwing the exception? It should work fine otherwise.查看堆栈跟踪或在这一行添加断点:
鉴于您发布的信息,除了一般评论之外,这个社区中的任何人都没有机会真正帮助您。
Look through the stack trace or add a breakpoint at this line:
Given the information you have posted there's no chance of anybody in this community really helping you beyond generic comments.
由于您没有显示初始化
_gc
的代码,我猜测这就是您发生 NullReferenceException 的地方。或者是
_gc.ChargeCancellation(
) 内部的某些内容引发了异常。如果您包含异常的完整文本,这可能会有所帮助,这样我们就可以准确地知道抛出异常的位置。
Since you show no code to initialize
_gc
, my guess is that is where your NullReferenceException is happening.Either that or something inside
_gc.ChargeCancellation(
) is throwing the Exception.It might help if you included the full text of the Exception so we knew exactly where the Exception was being thrown.