public static MethodCallCookie InvokeWithNoArgument <T>(this MethodInfo mi, T subject) { var pars = mi.GetParameters(); MethodCallCookie result = null; try { if (pars.IsSingleParamsArgument()) { var args = new[] { Activator.CreateInstance(pars[0].ParameterType.UnderlyingSystemType, 0) }; var retval = mi.Invoke(subject, args); result = new MethodCallCookie(mi, args, retval); } else { var retval = mi.Invoke(subject, Empty.ObjectArray); result = new MethodCallCookie(mi, Empty.ObjectArray, retval); } } catch { } return(result); }
public static MethodCallCookie InvokeWithArguments(this MethodInfo mi, object self, params object[] args) { MethodCallCookie result = null; try { var retval = mi.Invoke(self, args); result = new MethodCallCookie(mi, args, retval); } catch { // we cannot reasonably catch this } return(result); }
public static MethodCallCookie InvokeStaticWithSingleArgument <T>(this MethodInfo mi, T arg) { MethodCallCookie result = null; try { var args = new object[] { arg }; var retval = mi.Invoke(null /*static*/, args); result = new MethodCallCookie(mi, args, retval); } catch { // we cannot reasonably catch this } return(result); }