Exemple #1
0
        public TR InvokeFunc4 <A1, A2, A3, A4, TR> (object d, A1 a1, A2 a2, A3 a3, A4 a4)
        {
            Stats.Increment(StatsCounter.InvokeBinderInvoked);

            Func <A1, A2, A3, A4, TR> f = d as Func <A1, A2, A3, A4, TR>;

            if (f != null)
            {
                Stats.Increment(StatsCounter.InvokeBinderInvoked_Fast);

                return(f(a1, a2, a3, a4));
            }

            Stats.Increment(StatsCounter.InvokeBinderInvoked_Slow);

            Delegate del = (Delegate)d;

            sArgs [0] = a1;
            sArgs [1] = a2;
            sArgs [2] = a3;
            sArgs [3] = a4;
            bool canConvert = MethodBinder.ConvertArguments(del.Method, null, sArgs, 4, ref mConvertedArgs);

            Debug.Assert(canConvert, "Could not convert parameters");
            return((TR)del.DynamicInvoke(mConvertedArgs));
        }
Exemple #2
0
        public TR InvokeFunc9 <A1, A2, A3, A4, A5, A6, A7, A8, A9, TR> (object d, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
        {
            Stats.Increment(StatsCounter.InvokeBinderInvoked);

            Func <A1, A2, A3, A4, A5, A6, A7, A8, A9, TR> f = d as Func <A1, A2, A3, A4, A5, A6, A7, A8, A9, TR>;

            if (f != null)
            {
                Stats.Increment(StatsCounter.InvokeBinderInvoked_Fast);

                return(f(a1, a2, a3, a4, a5, a6, a7, a8, a9));
            }

            Stats.Increment(StatsCounter.InvokeBinderInvoked_Slow);

            Delegate del = (Delegate)d;

            sArgs [0] = a1;
            sArgs [1] = a2;
            sArgs [2] = a3;
            sArgs [3] = a4;
            sArgs [4] = a5;
            sArgs [5] = a6;
            sArgs [6] = a7;
            sArgs [7] = a8;
            sArgs [8] = a9;
            bool canConvert = MethodBinder.ConvertArguments(del.Method, null, sArgs, 9, ref mConvertedArgs);

            Debug.Assert(canConvert, "Could not convert parameters");
            return((TR)del.DynamicInvoke(mConvertedArgs));
        }
Exemple #3
0
        public void InvokeAction8 <A1, A2, A3, A4, A5, A6, A7, A8> (object d, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
        {
            Stats.Increment(StatsCounter.InvokeBinderInvoked);

            Action <A1, A2, A3, A4, A5, A6, A7, A8> a = d as Action <A1, A2, A3, A4, A5, A6, A7, A8>;

            if (a != null)
            {
                Stats.Increment(StatsCounter.InvokeBinderInvoked_Fast);

                a(a1, a2, a3, a4, a5, a6, a7, a8);
                return;
            }

            Stats.Increment(StatsCounter.InvokeBinderInvoked_Slow);

            Delegate del = (Delegate)d;

            sArgs [0] = a1;
            sArgs [1] = a2;
            sArgs [2] = a3;
            sArgs [3] = a4;
            sArgs [4] = a5;
            sArgs [5] = a6;
            sArgs [6] = a7;
            sArgs [7] = a8;
            bool canConvert = MethodBinder.ConvertArguments(del.Method, null, sArgs, 8, ref mConvertedArgs);

            Debug.Assert(canConvert, "Could not convert parameters");
            del.DynamicInvoke(mConvertedArgs);
        }
Exemple #4
0
        public void InvokeAction4 <A1, A2, A3, A4> (object d, A1 a1, A2 a2, A3 a3, A4 a4)
        {
            Stats.Increment(StatsCounter.InvokeBinderInvoked);

            Action <A1, A2, A3, A4> a = d as Action <A1, A2, A3, A4>;

            if (a != null)
            {
                Stats.Increment(StatsCounter.InvokeBinderInvoked_Fast);

                a(a1, a2, a3, a4);
                return;
            }

            Stats.Increment(StatsCounter.InvokeBinderInvoked_Slow);

            Delegate del = (Delegate)d;

            sArgs [0] = a1;
            sArgs [1] = a2;
            sArgs [2] = a3;
            sArgs [3] = a4;
            bool canConvert = MethodBinder.ConvertArguments(del.Method, null, sArgs, 4, ref mConvertedArgs);

            Debug.Assert(canConvert, "Could not convert parameters");
            del.DynamicInvoke(mConvertedArgs);
        }
Exemple #5
0
        public void InvokeAction2 <A1, A2> (object d, A1 a1, A2 a2)
        {
            Stats.Increment(StatsCounter.InvokeBinderInvoked);

            TypeLogger.LogType(d);

            Action <A1, A2> a = d as Action <A1, A2>;

            if (a != null)
            {
                a(a1, a2);
                return;
            }

            Stats.Increment(StatsCounter.InvokeBinderInvoked_Slow);

            Delegate del = (Delegate)d;

            sArgs [0] = a1;
            sArgs [1] = a2;
            bool canConvert = MethodBinder.ConvertArguments(del.Method, null, sArgs, 2, ref mConvertedArgs);

            Debug.Assert(canConvert, "Could not convert parameters");
            del.DynamicInvoke(mConvertedArgs);
        }
Exemple #6
0
        public TR InvokeFunc1 <A1, TR> (object d, A1 a1)
        {
            Stats.Increment(StatsCounter.InvokeBinderInvoked);

            TypeLogger.LogType(d);

            Func <A1, TR> f = d as Func <A1, TR>;

            if (f != null)
            {
                Stats.Increment(StatsCounter.InvokeBinderInvoked_Fast);

                return(f(a1));
            }

            Stats.Increment(StatsCounter.InvokeBinderInvoked_Slow);

            Delegate del = (Delegate)d;

            sArgs [0] = a1;
            bool canConvert = MethodBinder.ConvertArguments(del.Method, null, sArgs, 1, ref mConvertedArgs);

            Debug.Assert(canConvert, "Could not convert parameters");
            return((TR)del.DynamicInvoke(mConvertedArgs));
        }
Exemple #7
0
        public TR InvokeFunc0 <TR> (object d)
        {
            Stats.Increment(StatsCounter.InvokeBinderInvoked);

            Func <TR> f = d as Func <TR>;

            if (f != null)
            {
                Stats.Increment(StatsCounter.InvokeBinderInvoked_Fast);

                return(f());
            }

            Stats.Increment(StatsCounter.InvokeBinderInvoked_Slow);

            Delegate del        = (Delegate)d;
            bool     canConvert = MethodBinder.ConvertArguments(del.Method, null, sArgs, 0, ref mConvertedArgs);

            Debug.Assert(canConvert, "Could not convert parameters");
            return((TR)del.DynamicInvoke(mConvertedArgs));
        }
Exemple #8
0
        public void InvokeAction0(object d)
        {
            Stats.Increment(StatsCounter.InvokeBinderInvoked);

            Action a = d as Action;

            if (a != null)
            {
                Stats.Increment(StatsCounter.InvokeBinderInvoked_Fast);

                a();
                return;
            }

            Stats.Increment(StatsCounter.InvokeBinderInvoked_Slow);

            Delegate del        = (Delegate)d;
            bool     canConvert = MethodBinder.ConvertArguments(del.Method, null, sArgs, 0, ref mConvertedArgs);

            Debug.Assert(canConvert, "Could not convert parameters");
            del.DynamicInvoke(mConvertedArgs);
        }
        private object ResolveAndInvoke(object o, int argCount)
        {
            // determine object type
            Type otype;
            bool isStatic;

            if (o is Type)
            {
                // this is a static method invocation where o is the class
                otype    = (Type)o;
                isStatic = true;
            }
            else
            {
                // this is a instance method invocation
                otype    = o.GetType();
                isStatic = false;
            }

            // see if type has changed
            if (otype != mType)
            {
                // re-resolve method list if type has changed
                mType = otype;

                // get method list for type and method name
                BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public;
                if (isStatic)
                {
                    flags |= BindingFlags.Static;
                }
                else
                {
                    flags |= BindingFlags.Instance;
                }

                mMethodList = MethodBinder.LookupMethodList(mType, this.name, flags, argCount);

                // select new method to use
                SelectMethod(o, argCount);
            }
            else if (mIsOverloaded)
            {
                // if there are overloads we select the method every time
                // we could look into a more optimal way of doing this if it becomes a problem
                SelectMethod(o, argCount);
            }

            if (mDelegate == null)
            {
                // invoke as method
                // convert arguments for method
                if (mMethod.ConvertArguments(o, mArgs, argCount, ref mConvertedArgs))
                {
                    // invoke method with converted arguments
                    return(mMethod.Method.Invoke(o, mConvertedArgs));
                }
            }
            else
            {
                // invoke as delegate
                // convert arguments for delegate and invoke
                object[] newargs = PlayScript.Dynamic.ConvertArgumentList(mDelegate.Method, mArgs);
                return(mDelegate.DynamicInvoke(newargs));
            }

            throw new InvalidOperationException("Could not find suitable method to invoke: " + this.name + " for type: " + mType);
        }