I'm trying to dynamically invoke a member on a specific type using CoreCLR, but the method Type.InvokeMember is not available when compiling against DNXCORE50. However, if I compile against DNX451 it works fine.
Below is a sample of how this can be achieved using DNX451, but how can I do the same in DNXCORE50?
using System;
using System.Reflection;
namespace InvokeMember
{
public class Program
{
public void Main(string[] args)
{
typeof (Program).InvokeMember("DoStuff", BindingFlags.InvokeMethod, null, new Program(), null);
}
public void DoStuff()
{
Console.WriteLine("Doing stuff");
}
}
}
With this code, it works :
MethodInfo method = typeof(Program).GetTypeInfo().GetDeclaredMethod("DoStuff");
method.Invoke(new Program(), null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With