Snipps by Patrik

How To Invoke An Async Method Using Reflection In C#

Here’s an example of how to invoke a private method using reflection in .NET:

MyClass myClass = new MyClass();
Type classType = myClass.GetType();
MethodInfo methodInfo = classType.GetMethod("MethodName",
                BindingFlags.Instance | BindingFlags.NonPublic);
 
// Make an invocation:
var result = await (dynamic)methodInfo.Invoke(myClass, null);

Comments

Leave a Comment

All fields are required. Your email address will not be published.