Skip to content

Instantly share code, notes, and snippets.

@szul
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szul/d3c962c1b3f9cc0aa4cd to your computer and use it in GitHub Desktop.
Save szul/d3c962c1b3f9cc0aa4cd to your computer and use it in GitHub Desktop.
Dynamic method invocation
/*
* 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