如何发出对[mscorlib] System.Console :: Write(char)的调用?

And*_*ech 2 c# reflection reflection.emit

我目前正在拨打[mscorlib]System.Console::Write(char)以下电话:

ilg.EmitCall(OpCodes.Call,
             typeof(Console).GetMethods().First(m =>
                 m.Name == "Write" && m.GetParameters().Length == 1 &&
                 m.GetParameters().Any(p => p.ParameterType == typeof(char))),
             null);
Run Code Online (Sandbox Code Playgroud)

但有没有一种更清晰的方法可以引用该Console.Write(char)方法,可能没有实际迭代正式参数?

the*_*oop 8

尝试使用GetMethod,而不是GetMethods:

ilg.EmitCall(OpCodes.Call, 
  typeof(Console).GetMethod("Write", new[] { typeof(char) }),
  null);
Run Code Online (Sandbox Code Playgroud)