开发者

How to invoke generic lambda expressions?

开发者 https://www.devze.com 2023-01-09 19:37 出处:网络
private void ExecuteCommand(Expression<Func<bool>> command) { bool success = command.Compile().Invoke();
private void ExecuteCommand(Expression<Func<bool>> command)
{
    bool success = command.Compile().Invoke();
}

private void Test()
{
    ExecuteCommand开发者_如何学Go(() => _gc.ChargeCancellation(""));
}

With this code, I got a NullReferenceException.


Is _gc null by any chance? Or perhaps ChargeCancellation itself is throwing the exception? It should work fine otherwise.


Look through the stack trace or add a breakpoint at this line:

ExecuteCommand(() => _gc.ChargeCancellation(""));

Given the information you have posted there's no chance of anybody in this community really helping you beyond generic comments.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消