0

我试图使用反射来调用作为非静态类的一部分的内部静态方法。

类的例子:

public class Example
{
    internal static string ExampleMethod(string input, out string output)
    {
        output = String.Empty;
        return string.Empty;
    }
}

我的反思尝试:

var dynMethod = typeof(Example).GetMethod("ExampleMethod", BindingFlags.NonPublic | BindingFlags.Static);

此行抛出异常:

Exception has been thrown by the target of an invocation
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
4

0 回答 0