2010-07-30 50 views
0
private void ExecuteCommand(Expression<Func<bool>> command) 
{ 
    bool success = command.Compile().Invoke(); 
} 

private void Test() 
{ 
    ExecuteCommand(() => _gc.ChargeCancellation("")); 
} 

有了這段代碼,我得到了一個N​​ullReferenceException。如何調用泛型lambda表達式?

+0

你從哪裏得到一個NullReferenceExecption?什麼是_gc? – tster 2010-07-30 15:07:06

+0

'_gc'是否在你沒有發佈的代碼中被初始化? – unholysampler 2010-07-30 15:07:53

+0

_gc不爲空。 – Rookian 2010-07-30 15:38:30

回答

2

期待透過堆棧跟蹤或在此行中添加斷點:

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

鑑於你已經張貼有該社區沒有任何的機會,真正幫助你超越一般的評論信息。

3

_gc null有沒有機會?或者ChargeCancellation本身就是拋出異常?否則它應該工作正常。

1

既然你不顯示代碼來初始化_gc,我的猜測是你的NullReferenceException正在發生。

或者_gc.ChargeCancellation(裏面的東西都拋出異常。

如果您包含Exception的全文,那麼我們可以確切知道拋出Exception的位置,這可能會有所幫助。