How to use OUT parameter values returned from METHOD.INVOKE in C#
I am using C# 2.0,
I am trying to call webmethod of my webservice, please see below code sample:
try
{
Type objtype = Type.GetType(crisresult.ToString());
object obj = Activator.CreateInstance(objtype);
Object[] mArgs = new Object[methodArgs.Length + 1];
methodArgs.CopyTo(mArgs, 0);
mArgs.SetValue(obj, methodArgs.Length);
methodArgs = mArgs;
Object result = mi.Invoke(service, methodArgs);
JObject parsed = JObject.Parse(result.ToString());
// option 1) if you are just using primitives
foreach ( KeyValuePair<string, JToken> pair in parsed)
{
Console.WriteLine("{0}: {1}", pair.Key,开发者_如何学Go pair.Value);
}
}
Now in above code in my methodArgs
object array is having an out parameter(crisresult), now incase of any error returned from my webservice method Object result = mi.Invoke(service, methodArgs);
is shown in my out parameter, I am sure that my out parameter is the last object in my methodArgs
object array, I am looking to get that object and check for the error result returned from the webservice.
Please suggest!
Your methodArgs
will have been updated to account for any ref
/ out
parameters. Since you believe it is the last one:
object foo = methodArgs[methodArgs.Length-1];
精彩评论