vendredi 4 novembre 2016

trying to use GetMethod to initialise MethodInfo variable

I am trying to call a function by passing a string which contains the function name.

Below is my code, neither of which work. The problem is that my MethodInfo variable mi is always null.

In debug I used the GetMethods method to see all the functions that are listed. The function I am trying to call is listed, I have double checked the spelling. What am I doing wrong?

object[] paraArray = new object[] { corpAct, secEvents };
MethodInfo mi = this.GetType().GetMethod(corpAct.DelegateName);
mi.Invoke(this, paraArray);

Second attempt

Type[] paraTypes = new Type[] { typeof(IHoldingLog), typeof(SecurityEvent) };
object[] paraArray = new object[] { corpAct, secEvents };
MethodInfo mi = this.GetType().GetMethod(corpAct.DelegateName, paraTypes);
mi.Invoke(this, paraArray);

The function it is trying to call,

void myFunction(IHoldingLog log, SecurityEvent sec)





Aucun commentaire:

Enregistrer un commentaire