Call a method with reference parameters with Reflection

I need to call the void method with reflection, which has 2 normal parameters and the third parameter, which is a reference parameter. I saw a lot of problem reports, and everyone suggests using the GetMethod function instead of InvokeMember. I tried InvokeMember and it works, can someone explain to me why?

Class1 myreferenceparam = new Class1();
myobject.InvokeMember("MyMethod", BindingFlags.InvokeMethod | BindingFlags.Default, null, myobject, new object[] { myparam1, myparam2, myreferenceparam });
Response.Write(myreferenceparam.myfield);

The MyMethod method edits the myfield of class 1. Is my code correct or should I use GetMethod?

+3
source share
1 answer

GetMethod (MethodInfo), . , , MethodInfo null, InvokeMemeber .

InvokeMember, , , . , "MissingMethodException", , GetMethod.

0

Source: https://habr.com/ru/post/1757966/


All Articles