I want to invoke a method on a class that i have a reference to. The method that I want to call has a custom attributes. Currently I can find this attributes and call the property of my class Attribute.
is there a way to invoke that method ?
PS/ The project is written in vbnet, but I think the solution is the same in c#.
If you can find the attributes I guess you have the
MethodInfoof that method(s). Simply call theMethodInfo.Invokemethod, you have to specify the instance of the object you want to use (ornullif it’s a static method) and all the parameters to pass to the method (in the same order of the prototype).For example if you have to invoke a method with this prototype:
And you have a function to find that method (making a search for a given attribute):
You can find and invoke that method (of a hypothetical object
anObject) with this code: