lundi 29 juin 2015

Call a function in C# to using a string as a function name? [on hold]

The answer Which I have seen is using reflections: But when the parameter list being passed is null, it is throwing an exception: PFA a sample code:

string a = "ValSel";
Type type = typeof(Services);
//services is the class name
MethodInfo info = type.GetMethod(a);
 info.Invoke(a,null);

or

type.InvokeMember(a,BindingFlags.InvokeMethod | BindingFlags.Public, null, null, null);

Is there any mistake in the syntax? Kindly help me out :)





Aucun commentaire:

Enregistrer un commentaire