Created
September 27, 2013 20:19
-
-
Save afreeland/6734584 to your computer and use it in GitHub Desktop.
C#: Invoke Method from MethodInfo
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
// 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