c# - Call a method with reference params with Reflection -


I need to call zero method with reflection in which there is 2 common parameters and a reference param which is a third parameter . I have seen many posts about this problem and have suggested that everyone use the GetMethod function instead of InvokeMember. I have tried InvokeMember and it works, why can anyone explain me?

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

Method Edit Myfield of Field MyMethod Field 1 Is my code correct or should I use GetMethod anyway?

GetMethod will provide you method metadata (MethodInfo), to determine the method and take appropriate action Can be used. For example, if the method does not exist or can not be found, you will receive MethodInfo blank, and you can handle this method before calling invokememeber.

The suggested logic as the name InvokeMember will only call the method specified in the arguments. If the method is not found, then it will throw "missing control" so that you are losing the verification bit given by GetMethod.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -