Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }