samedi 30 janvier 2016

C# Type GetMethod() where parameter order is random

I am trying to get a method of an object, and it works fine if the parameters of the method match the order of the list of parameters I provide. I am trying to avoid this, so I do not have to worry about the order of parameter types in methods across different files. Here is what I have

MethodInfo mi = stateType.GetMethod("Entrance", typesToUse.ToArray());

In my test case, typesToUse only contains two instances of unique interfaces, IClass1 and IClass2 in that order.

If the Entrance method is : Entrance(IClass1 c1, IClass2 c2), it picks this method up. Although, if its Entrance(IClass2 c2, IClass1 c1), it will not and mi will then be null.

Is there a way around this? Perhaps a way to tell GetMethod to ignore parameter order?

Any help is appreciated and thank you.





Aucun commentaire:

Enregistrer un commentaire