2015-11-06 68 views
0

我有2類: - BasePageElement(父) 和行動(BasePageElement的孩子)。不能鍵入 '表達<System.Func <TP,Action>>' 轉換爲 '表達<System.Func <TP,BasePageElement >>'

我有2種方法:

public void Click(Expression<Func<TP, Action>> action) 
    { 
     WaitSomething(action); 
     some code 
    } 

    public void WaitSomething(Expression<Func<TP, BasePageElement>> action) 
    { 

    } 

所以我在點擊方法的問題,因爲類型表達< Func鍵< TP,動作>>無法轉換爲表達< Func鍵< TP,BasePageElement >>
如何我可以解決嗎?

回答

1

您的問題是您嘗試將子類(Action)轉換爲父類(BasePageElement)。這是不可能的。只有相反纔可能。

因此,你將不得不轉換手動 Expression<Func<TP, Action>>Expression<Func<TP, BasePageElement>> ,然後調用WaitForSomething與轉換後的值作爲參數。

+0

我如何手動將Expression >轉換爲Expression >? – iPogosov

+0

您需要編寫一個轉換器函數,將Action從Expression中移出並將其轉換爲BasePageelement。 – Thomas

相關問題