Call a private method using a String in VB.Net -
ok have class this.
namespace myspace public class classa private function methoda(prm boolean) boolean return false end function private function methodb() boolean return false end function end class public class classb private function methodc() boolean return true end function private function invokea() boolean dim methodobj methodinfo 'null pointer except below here methodobj = type.gettype("myspace.classa").getmethod("methoda") dim params boolean() = {false} return cbool(methodobj.invoke(new classa(), params)) end function end class end namespace
what trying here invoke method different class parameters using method. returns null pointer exception. why? went wrong?
you doing various things wrong. following code should work without problem:
dim obja classa = new classa() methodobj = obja.gettype().getmethod("methoda", bindingflags.instance or bindingflags.nonpublic) dim params object() = {false} methodobj.invoke(obja, params)
you have various errors shouldn't allow code run @ all, namely:
- you retrieving private method without adequate
bindingflags
. - you not passing arguments
object
type.
additionally, not using getmethod
instantiated object of classa
(e.g., obja
above) , instance.gettype()
; not 100% sure need (perhaps can accomplish intend), performing step pretty quick process , allow code above work without problem.
Comments
Post a Comment