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?
source
share