Hello;
I want to refactor this method by extracting:
InfoOrdreDirect_5013 directOrder = new InfoOrdreDirect_5013();
directOrder.put_AIS(0, e_Type_Lecteur_CB.Type_Lecteur_CB_Satellite);
as a parameter, so I started with a delegate but it does not work
private void AutozeroPosition()
{
InfoOrdreDirect_5013 directOrder = new InfoOrdreDirect_5013();
directOrder.put_AIS(0, e_Type_Lecteur_CB.Type_Lecteur_CB_Satellite);
IInfoReponse_CRO reponseCro = null;
try
{
reponseCro = this._espCom.SendCmd(directOrder);
if (reponseCro != null && true)
{
}
}
catch (Exception ex)
{
Thread.Sleep(1000);
throw new System.Runtime.InteropServices.COMException(ex.Message);
}
}
My refactoring:
private delegate IInfoOrdreDirect InfoOrderDelegate(int a, Enum pegase);
private void AutozeroPosition(InfoOrdreDirect info, Delegate method, object[] param)
{
method.DynamicInvoke(param);
object infoReponseCro;
try
{
infoReponseCro = _espCom.SendCmd(info) as InfoReponse_CRO;
if (infoReponseCro != null && true)
{
}
}
catch (Exception ex)
{
Thread.Sleep(1000);
throw new System.Runtime.InteropServices.COMException(ex.Message);
}
}
My invoking:
InfoOrdreDirect_5013 info = new InfoOrdreDirect_5013();
AutozeroPosition(info, new InfoOrderDelegate(info.put_AIS),new object[] { 0, e_Type_Lecteur_CB.Type_Lecteur_CB_Satellite });
My error:
On put_ais:
Expected a method with infoOrderDirect put_ais(int, enum) signature.
Any Idea how to refactor the AutozeroPosition() ?
Thanks.
[edit]Code block added - OriginalGriff[/edit]