C#反射调用私有方法

来源:互联网 发布:手机防监控软件 编辑:程序博客网 时间:2024/06/06 00:50
 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 0
原创粉丝点击