c# - Why can't I retrieve the value for parameters of type out or ref using Type.InvokeMember? -


a long title, wanted specific. title question. though method invokemember calling has out parameter , assigning value to parameter can't grab value. here code using:

string parameter = ""; int result = convert.toint32(typeof(ability).invokemember(selectedmove, bindingflags.invokemethod | bindingflags.public | bindingflags.static, null, null, new object[] { parameter })); 

i changed this, makes work intended don't know why:

object[] args = new object[1];      //necessary retrieve ref/out parameter int result = convert.toint32(typeof(ability).invokemember(selectedmove, bindingflags.invokemethod | bindingflags.public | bindingflags.static, null, null, args)); 

in first code example, call invokemember doesn't modify value of parameter variable, replaces first item in parameter array (which points different string instance). since didn't keep reference array, can't retrieve value of output parameter.

in other words: array contains copy of parameter variable (i.e. copy of reference empty string). after call, parameter , value in array refer 2 different string instances.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

node.js - How to mock a third-party api calls in the backend -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -