mercredi 9 août 2017

C# MethodInfo Invoke() with JSON args

the Invoke() function on a MethodInfo object accepts parameters as an object[]. I want to be able to send a JSON encoded string instead. Is there any way to do this?

The code which i am basing mine of comes from this MSDN page

....
object wsvcClass = results.CompiledAssembly.CreateInstance(serviceName);
MethodInfo mi = wsvcClass.GetType().GetMethod(methodName);

//args in this case is an object[]. any way to pass a string?
return mi.Invoke(wsvcClass, args);

I am aware that Newtonsoft provides a way to deserialize strings but can it do so into an object[]? or is there another way to do this?





Aucun commentaire:

Enregistrer un commentaire