hen*_*gst 6 c# reflection coreclr dnx
我正在尝试使用CoreCLR动态调用特定类型的成员,但是在针对DNXCORE50进行编译时,方法Type.InvokeMember不可用.但是,如果我针对DNX451编译它可以正常工作.
下面是使用DNX451如何实现这一目标的示例,但我如何在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");
}
}
}
Run Code Online (Sandbox Code Playgroud)
使用这段代码,它可以工作:
MethodInfo method = typeof(Program).GetTypeInfo().GetDeclaredMethod("DoStuff");
method.Invoke(new Program(), null);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1172 次 |
| 最近记录: |