Created
February 6, 2018 16:24
-
-
Save nikomoravec/b56709ebc8a32965c2246448e4e925bd to your computer and use it in GitHub Desktop.
Call private methods in C#
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
using System; | |
using System.Reflection; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
A a = new A(); | |
System.Reflection.MethodInfo method = a.GetType().GetMethod("Foo", BindingFlags.NonPublic | BindingFlags.Instance); | |
method.Invoke(a, new object[] { }); | |
} | |
} | |
public class A | |
{ | |
void Foo () | |
{ | |
Console.WriteLine("Hello from reflection"); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment