简体   繁体   English

在执行之前传递lambda表达式的方法参数类型

[英]Method parameter type to pass a lambda expression prior to execute

I am trying to retrofit some interface based abstraction to legacy code as a preliminary step for Dependency Injection. 我试图将一些基于接口的抽象改进为遗留代码,作为依赖注入的初步步骤。 The legacy code contains lambda usage that I am struggling to encapsulate. 遗留代码包含我正在努力封装的lambda用法。 Here is the existing lambda usage: 这是现有的lambda用法:

private void MethodAaa(EntityA a, EntityB a, int someInt) {...}

private void MethodBbb(DateTime date, EntityA e) {...}


_commandObjectFromThirdPartyLibrary.Execute(() => MethodAaa(a, b, c));

_commandObjectFromThirdPartyLibrary.Execute(() => MethodBbb(d, e));

I wish to route the lamda execution via a common base class method as follows: 我希望通过公共基类方法路由lamda执行,如下所示:

base.CommonExecute( () => MethodAaa(a, b, c) );
base.CommonExecute( () => MethodBbb(d, e) );

base.CommonExecute( Action<???> lamdaExpression )
{
    _commandObjectFromThirdPartyLibrary.Execute( lamdaExpression );
}

Can someone provide an example of how to declare base.CommonExecute(?) properly? 有人可以提供一个如何正确声明base.CommonExecute(?)的示例吗?

I don't see anything wrong with using the non-generic version of the Action delegate : 我没有看到使用Action代理非泛型版本有什么问题:

base.CommonExecute(Action lambdaExpression )
{
    _commandObjectFromThirdPartyLibrary.Execute( lambdaExpression );
}

非泛型版本的Action是void-void one:

public delegate void Action();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM