How to pass a parameter as a reference with MethodInfo.Invoke

前端 未结 2 1544
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 05:39

How can I pass a parameter as a reference with MethodInfo.Invoke?

This is the method I want to call:

private static bool test(string str,          


        
2条回答
  •  醉酒成梦
    2020-11-30 06:00

    When a method invoked by reflection has a ref parameter it will be copied back into the array that was used as an argument list. So to get the copied back reference you simply need to look at the array used as arguments.

    object[] args = new [] { "test", rawAsm };
    bool b = (bool)_lf.Invoke(null, args);
    

    After this call args[1] will have the new byte[]

提交回复
热议问题