Reflection Invoke question
Monkey Forums/Monkey Programming/Reflection Invoke question
| ||
Has anyone solved this in reflection? When I want to use MethodInfo.Invoke() I need to pass an array for parameters. What if the method I want to invoke does not require parameters? I cannot pass Null as the parameter as that throws a compile error. update: adding a new array, say using Local params:Int[1] , will result in the error: Unable to find overload for Invoke(object,Int[]) I know where that is coming from. But how to fix it? |
| ||
Did you try with "Void" or a null array ( "[]" ) ? |
| ||
Null array I did try, Void: no. I will give that a shot. edit: Bothh of these don't work. This is a real problem atm. Boxing a value (as the documentation suggests) is also not working. I am then getting "Cannot find overload for Invoke(object, object)" |
| ||
Hi, Use an empty array, eg: Import reflection Class C Method Update() Print "C.Update!" End End Function Main() Local c:=GetClass( "C" ) Local i:=c.NewInstance() Local m:=c.GetMethod( "Update",[] ) m.Invoke( i,[] ) End |
| ||
Ah, the trick is using an emtpy array when using GetMethod(). Thanks! |