2015-11-06 38 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

相关问题