Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type.InvokeMember(..) in CoreCLR

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");
        }
    }

}
like image 843
henningst Avatar asked Nov 18 '15 15:11

henningst


1 Answers

With this code, it works :

        MethodInfo method = typeof(Program).GetTypeInfo().GetDeclaredMethod("DoStuff");
        method.Invoke(new Program(), null);
like image 69
aguetat Avatar answered Sep 18 '22 17:09

aguetat