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: