Last active
August 29, 2015 14:20
-
-
Save szul/d3c962c1b3f9cc0aa4cd to your computer and use it in GitHub Desktop.
Dynamic method invocation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* You will need "using System.Reflection;" | |
* The variable "method" is a string that represents the case-sensitive name of the method to be called. | |
* The variable "context" in this instance is the HttpContext, but can be any variable(s) the method expects. | |
* In this example the called method returns a string, so the invocation is cast into a string, but this can change based on what the method returns. | |
*/ | |
Type _t = this.GetType(); | |
MethodInfo _methodInfo = _t.GetMethod(method); | |
string result = (String)_methodInfo.Invoke(this, new object[] { context }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment