How to invoke generic lambda expressions?
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.
精彩评论