vb.net - Calling a method inside the class from a method list -
ok have class this
public notinheritable class helper private function a(a string) boolean return true end function private function b(a string) boolean return true end function end class
now want call string name want get list of methods inside of instantiated object of class(if can returned array fine)
dim h new helper() 'so list '[0] - '[1] - b
and want acquire name of 2nd method(which method b) , call using name
dim methodobj methodinfo methodobj = type.gettype("common.validation.helper").getmethod(returnafunction(1)) methodobj.invoke(new helper(), params))
is possible? if not how can make closer on want? thanks
given instance h
:
dim h new helper()
you can use getmethods()
:
dim yourprivatemethods = h.gettype() _ .getmethods(bindingflags.nonpublic or bindingflags.instance) _ .where(function(m) not m.ishidebysig) _ .toarray() '' array contains , b '' method named 'b' , call yourprivatemethods.single(function(m) m.name = "b").invoke(h, {"the parameter"})
or getmethod(name)
:
h.gettype().getmethod("b", bindingflags.nonpublic or bindingflags.instance).invoke(h, {"the parameter"})
note that, since methods private, have use appropriate bindingflags
.
Comments
Post a Comment