Skip to content

Instantly share code, notes, and snippets.

@afreeland
Created September 27, 2013 20:19
Show Gist options
  • Save afreeland/6734584 to your computer and use it in GitHub Desktop.
Save afreeland/6734584 to your computer and use it in GitHub Desktop.
C#: Invoke Method from MethodInfo
// Define our Methods
private static MethodInfo containsMethod = typeof(string).GetMethod("Contains", new[] { typeof(string) });
private static MethodInfo startsWithMethod = typeof(string).GetMethod("StartsWith", new[] { typeof(string) });
private static MethodInfo endsWithMethod = typeof(string).GetMethod("EndsWith", new[] { typeof(string) })
// How to use (Invoke) our Method
containsMethod.Invoke("FirstName", new object[]{"First"}); // returns true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment