Getting a return value from a methodInfo.invoke
Asked Answered
R

1

26

How do I get a return value (int) from a methodInfo.invoke?

What makes it difficult for me is the fact that I use a string variable to call the method.

Check the example below:

if (Convert.ToBoolean(getParameterFromXML("issue", k, 1)) == true)
{
    m = k + 1;

    MethodInfo methodInfo = typeof(frmDetails).GetMethod("Issue" + m);
    methodInfo.Invoke(this, Parameters);

}

What can I do? Any help would be appreciated.

Ratchford answered 21/9, 2012 at 8:10 Comment(0)
M
43

When I read this you get the result of the method back from the Invoke-call. It is returned as an object so you need to cast it to a specific type.

var returnValue = (int) methodInfo.Invoke(this, Parameters);
Musketry answered 21/9, 2012 at 8:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.