我正在尝试使用反射来调用内部静态方法,该方法是非静态类的一部分。
课程示例:
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)