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. Here is the existing lambda usage:
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:
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?
I don't see anything wrong with using the non-generic version of the Action delegate :
base.CommonExecute(Action lambdaExpression )
{
_commandObjectFromThirdPartyLibrary.Execute( lambdaExpression );
}
非泛型版本的Action是void-void one:
public delegate void Action();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.