0
点赞
收藏
分享

微信扫一扫

C#反射调用私有方法

汤姆torn 2022-11-23 阅读 85


public object CallNonPublicMethod(object instance, string methodName, object[] param)
{
Type type = instance.GetType();
MethodInfo method = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic);
object result;
try
{
result = method.Invoke(instance, param);
}
catch (TargetInvocationException ex)
{
throw ex.InnerException;
}
return result;
}


举报

相关推荐

0 条评论