Home
Manage Your Code
Snippet: Call private method by method name (C#)
Title: Call private method by method name Language: C#
Description: You have a class with a private method. From within the class, you want to call the private method by method name instead of calling the method directly. Views: 89
Author: Mark Nugent Date Added: 7/7/2008
Copy Code  
1MethodInfo methodInfo = this.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic);
2methodInfo.Invoke(this, args);
3
4//note: use BindingFlags.Static if the private method is static