예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImpromptuRelayCommand"/> class.
 /// </summary>
 /// <param name="executeTarget">The execute target.</param>
 /// <param name="executeName">Name of the execute.</param>
 /// <param name="setup">The setup which has the on error event</param>
 public ImpromptuRelayCommand(object executeTarget, String_OR_InvokeMemberName executeName, ISetupViewModel setup = null)
 {
     _executeTarget      = executeTarget;
     _setup              = setup;
     _executeInvoke      = new CacheableInvocation(InvocationKind.InvokeMemberAction, executeName, 1);
     _executeInvokeNoArg = new CacheableInvocation(InvocationKind.InvokeMemberAction, executeName, 0);
 }
예제 #2
0
        internal static CallSite <T> CreateCallSite <T>(
            Type specificBinderType,
            int knownType,
            LazyBinder binder,
            String_OR_InvokeMemberName name,
            Type context,
            string[] argNames  = null,
            bool staticContext = false,
            bool isEvent       = false
            )
            where T : class
        {
            var tHash = BinderHash <T> .Create(name, context, argNames, specificBinderType, staticContext, isEvent, knownType != Unknown);

            lock (_binderCacheLock)
            {
                CallSite tOut;
                if (!TryDynamicCachedCallSite(tHash, knownType, out tOut))
                {
                    tOut = CallSite <T> .Create(binder());

                    SetDynamicCachedCallSite(tHash, knownType, tOut);
                }
                return((CallSite <T>)tOut);
            }
        }
예제 #3
0
        internal static void InvokeMemberActionCallSite(object target, String_OR_InvokeMemberName name, object[] args, string[] tArgNames, Type tContext, bool tStaticContext, ref CallSite callSite)
        {
            LazyBinder tBinder     = null;
            Type       tBinderType = null;

            if (callSite == null)
            {
                tBinder = () => {
                    IEnumerable <CSharpArgumentInfo> tList;
                    tList = GetBindingArgumentList(args, tArgNames, tStaticContext);

                    var tFlag = CSharpBinderFlags.ResultDiscarded;
                    if (name.IsSpecialName)
                    {
                        tFlag |= CSharpBinderFlags.InvokeSpecialName;
                    }

                    return(Binder.InvokeMember(tFlag, name.Name, name.GenericArgs,
                                               tContext, tList));
                };
                tBinderType = typeof(InvokeMemberBinder);
            }

            InvokeMemberAction(ref callSite, tBinderType, tBinder, name, tStaticContext, tContext, tArgNames, target, args);
        }
예제 #4
0
        /// <summary>
        /// Creates the cacheable method or indexer or property call.
        /// </summary>
        /// <param name="kind">The kind.</param>
        /// <param name="name">The name.</param>
        /// <param name="callInfo">The callInfo.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public static CacheableInvocation CreateCall(InvocationKind kind, String_OR_InvokeMemberName name = null, CallInfo callInfo = null, object context = null)
        {
            var tArgCount = callInfo != null ? callInfo.ArgumentCount : 0;
            var tArgNames = callInfo != null?callInfo.ArgumentNames.ToArray() : null;

            return(new CacheableInvocation(kind, name, tArgCount, tArgNames, context));
        }
        /// <summary>
        /// Creates the cacheable method or indexer or property call.
        /// </summary>
        /// <param name="kind">The kind.</param>
        /// <param name="name">The name.</param>
        /// <param name="callInfo">The callInfo.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public static CacheableInvocation CreateCall(InvocationKind kind, String_OR_InvokeMemberName name = null, CallInfo callInfo = null,object context = null)
        {
            var tArgCount = callInfo != null ? callInfo.ArgumentCount : 0;
            var tArgNames = callInfo != null ? callInfo.ArgumentNames.ToArray() : null;

            return new CacheableInvocation(kind, name, tArgCount, tArgNames, context);
        }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImpromptuRelayCommand"/> class.
 /// </summary>
 /// <param name="executeTarget">The execute target.</param>
 /// <param name="executeName">Name of the execute method.</param>
 /// <param name="canExecuteTarget">The can execute target.</param>
 /// <param name="canExecuteName">Name of the can execute method.</param>
 public ImpromptuRelayCommand(object executeTarget, String_OR_InvokeMemberName executeName, object canExecuteTarget, String_OR_InvokeMemberName canExecuteName, ISetupViewModel setup = null)
     : this(executeTarget, executeName, setup)
 {
     _canExecuteTarget      = canExecuteTarget;
     _canExecuteInvoke      = new CacheableInvocation(InvocationKind.InvokeMember, canExecuteName, 1);
     _canExecuteInvokeGet   = new CacheableInvocation(InvocationKind.Get, canExecuteName);
     _canExecuteInvokeNoArg = new CacheableInvocation(InvocationKind.InvokeMember, canExecuteName);
 }
예제 #7
0
 internal static TReturn InvokeMember <TReturn>(ref CallSite callsite, Type binderType, LazyBinder binder,
                                                String_OR_InvokeMemberName name,
                                                bool staticContext,
                                                Type context,
                                                string[] argNames,
                                                object target, params object[] args)
 {
     return(InvokeMemberTargetType <object, TReturn>(ref callsite, binderType, binder, name, staticContext, context, argNames, target, args));
 }
예제 #8
0
파일: BinderHash.cs 프로젝트: caoxk/coapp
 protected BinderHash(Type delegateType, String_OR_InvokeMemberName name, Type context, string[] argNames, Type binderType, bool staticContext, bool isEvent)
 {
     BinderType    = binderType;
     StaticContext = staticContext;
     DelegateType  = delegateType;
     Name          = name;
     Context       = context;
     ArgNames      = argNames;
     IsEvent       = isEvent;
 }
예제 #9
0
 protected BinderHash(Type delegateType, String_OR_InvokeMemberName name, Type context, string[] argNames, Type binderType, bool staticContext, bool isEvent)
 {
     BinderType = binderType;
     StaticContext = staticContext;
     DelegateType = delegateType;
     Name = name;
     Context = context;
     ArgNames = argNames;
     IsEvent = isEvent;
 }
예제 #10
0
 protected BinderHash(Type delegateType, String_OR_InvokeMemberName name, Type context, string[] argNames, Type binderType, bool staticContext, bool isEvent, bool knownBinder)
 {
     this.KnownBinder   = knownBinder;
     this.BinderType    = binderType;
     this.StaticContext = staticContext;
     this.DelegateType  = delegateType;
     this.Name          = name;
     this.Context       = context;
     this.ArgNames      = argNames;
     this.IsEvent       = isEvent;
 }
예제 #11
0
        internal static object InvokeMemberCallSite(object target, String_OR_InvokeMemberName name, object[] args, string[] tArgNames, Type tContext, bool tStaticContext, ref CallSite callSite)
        {
            LazyBinder tBinder     = null;
            Type       tBinderType = null;

            if (callSite == null)
            {
                tBinder = () => {
                    var tList = GetBindingArgumentList(args, tArgNames, tStaticContext);
                    var tFlag = CSharpBinderFlags.None;
                    if (name.IsSpecialName)
                    {
                        tFlag |= CSharpBinderFlags.InvokeSpecialName;
                    }
                    return(Binder.InvokeMember(tFlag, name.Name, name.GenericArgs,
                                               tContext, tList));
                };
                tBinderType = typeof(InvokeMemberBinder);
            }

            return(InvokeMember <object>(ref callSite, tBinderType, tBinder, name, tStaticContext, tContext, tArgNames, target, args));
        }
예제 #12
0
        internal static CallSite CreateCallSite(
            Type delegateType,
            Type specificBinderType,
            LazyBinder binder,
            String_OR_InvokeMemberName name,
            Type context,
            string[] argNames  = null,
            bool staticContext = false,
            bool isEvent       = false
            )
        {
            var tHash = BinderHash.Create(delegateType, name, context, argNames, specificBinderType, staticContext, isEvent);

            lock (_binderCacheLock) {
                CallSite tOut;
                if (!_binderCache.TryGetValue(tHash, out tOut))
                {
                    tOut = CallSite.Create(delegateType, binder());
                    _binderCache[tHash] = tOut;
                }
                return(tOut);
            }
        }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Invocation"/> class.
 /// </summary>
 /// <param name="kind">The kind.</param>
 /// <param name="name">The name.</param>
 /// <param name="storedArgs">The args.</param>
 public Invocation(InvocationKind kind, String_OR_InvokeMemberName name, params object[] storedArgs)
 {
     Kind = kind;
     Name = name;
     Args = storedArgs;
 }
예제 #14
0
 /// <summary>
 /// Creates the invocation.
 /// </summary>
 /// <param name="kind">The kind.</param>
 /// <param name="name">The name.</param>
 /// <param name="storedArgs">The args.</param>
 /// <returns></returns>
 public static Invocation Create(InvocationKind kind, String_OR_InvokeMemberName name, params object[] storedArgs)
 {
     return(new Invocation(kind, name, storedArgs));
 }
예제 #15
0
        internal static void InvokeMemberAction(ref CallSite callsite,
                                                Type binderType,
                                                int knownType,
                                                LazyBinder binder,
                                                String_OR_InvokeMemberName name,
                                                bool staticContext,
                                                Type context,
                                                string[] argNames,
                                                object target,
                                                params object [] args)
        {
            var tSwitch = args.Length;

            switch (tSwitch)
            {
                #region Optimizations
            case 0:
            {
                var tCallSite = (CallSite <Action <CallSite, object> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Action <CallSite, object> >(binderType, knownType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                tCallSite.Target(tCallSite, target);
                break;
            }

            case 1:
            {
                var tCallSite = (CallSite <Action <CallSite, object, object> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Action <CallSite, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                tCallSite.Target(tCallSite, target, args[0]);
                break;
            }

            case 2:
            {
                var tCallSite = (CallSite <Action <CallSite, object, object, object> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Action <CallSite, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                tCallSite.Target(tCallSite, target, args[0], args[1]);
                break;
            }

            case 3:
            {
                var tCallSite = (CallSite <Action <CallSite, object, object, object, object> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Action <CallSite, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                tCallSite.Target(tCallSite, target, args[0], args[1], args[2]);
                break;
            }

            case 4:
            {
                var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3]);
                break;
            }

            case 5:
            {
                var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4]);
                break;
            }

            case 6:
            {
                var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object, object> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5]);
                break;
            }

            case 7:
            {
                var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object, object, object> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
                break;
            }

            case 8:
            {
                var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object, object, object, object> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);
                break;
            }

            case 9:
            {
                var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]);
                break;
            }

            case 10:
            {
                var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]);
                break;
            }

            case 11:
            {
                var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object, object> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10]);
                break;
            }

            case 12:
            {
                var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object, object, object> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11]);
                break;
            }

            case 13:
            {
                var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object, object, object, object> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12]);
                break;
            }

            case 14:
            {
                var tCallSite = (CallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Action <CallSite, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object> >(binderType, knownType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13]);
                break;
            }

                #endregion
            default:
                var tArgTypes     = Enumerable.Repeat(typeof(object), tSwitch);
                var tDelagateType = BuildProxy.GenerateCallSiteFuncType(tArgTypes, typeof(void));
                Impromptu.InvokeCallSite(CreateCallSite(tDelagateType, binderType, knownType, binder, name, context, argNames), target, args);
                break;
            }
        }
예제 #16
0
        internal static TReturn InvokeMemberTargetType <TTarget, TReturn>(
            ref CallSite callsite,
            Type binderType,
            LazyBinder binder,
            String_OR_InvokeMemberName name,
            bool staticContext,
            Type context,
            string[] argNames,
            TTarget target, params object [] args)
        {
            var tSwitch = args.Length;

            switch (tSwitch)
            {
            case 0:
            {
                var tCallSite = (CallSite <Func <CallSite, TTarget, TReturn> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Func <CallSite, TTarget, TReturn> >(binderType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                return(tCallSite.Target(tCallSite, target));
            }

            case 1:
            {
                var tCallSite = (CallSite <Func <CallSite, TTarget, object, TReturn> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Func <CallSite, TTarget, object, TReturn> >(binderType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                return(tCallSite.Target(tCallSite, target, args[0]));
            }

            case 2:
            {
                var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, TReturn> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                return(tCallSite.Target(tCallSite, target, args[0], args[1]));
            }

            case 3:
            {
                var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, TReturn> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2]));
            }

            case 4:
            {
                var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, TReturn> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3]));
            }

            case 5:
            {
                var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, TReturn> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4]));
            }

            case 6:
            {
                var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, object, TReturn> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5]));
            }

            case 7:
            {
                var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, TReturn> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6]));
            }

            case 8:
            {
                var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, TReturn> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]));
            }

            case 9:
            {
                var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, TReturn> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]));
            }

            case 10:
            {
                var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, TReturn> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]));
            }

            case 11:
            {
                var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, object, TReturn> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10]));
            }

            case 12:
            {
                var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, object, object, TReturn> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11]));
            }

            case 13:
            {
                var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, object, object, object, TReturn> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12]));
            }

            case 14:
            {
                var tCallSite = (CallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, object, object, object, object, TReturn> >)callsite;
                if (tCallSite == null)
                {
                    tCallSite = CreateCallSite <Func <CallSite, TTarget, object, object, object, object, object, object, object, object, object, object, object, object, object, object, TReturn> >(binderType, binder, name, context, argNames, staticContext);
                    callsite  = tCallSite;
                }
                return(tCallSite.Target(tCallSite, target, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13]));
            }

            default:
                var tArgTypes     = Enumerable.Repeat(typeof(object), tSwitch);
                var tDelagateType = BuildProxy.GenerateCallSiteFuncType(tArgTypes, typeof(TTarget));
                return(Impromptu.InvokeCallSite(CreateCallSite(tDelagateType, binderType, binder, name, context, argNames), target, args));
            }
        }
예제 #17
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="Invocation" /> class.
 /// </summary>
 /// <param name="kind"> The kind. </param>
 /// <param name="name"> The name. </param>
 /// <param name="storedArgs"> The args. </param>
 public Invocation(InvocationKind kind, String_OR_InvokeMemberName name, params object[] storedArgs)
 {
     Kind = kind;
     Name = name;
     Args = storedArgs;
 }
        /// <summary>
        /// Invokes the static method.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="args">The args.</param>
        /// <returns></returns>
        protected object InvokeStaticMethod(String_OR_InvokeMemberName name, object[] args)
        {
            var staticType = InvokeContext.CreateStatic;
            var nameArgs = InvokeMemberName.Create;

            var tList = new List<object> { CallTarget };
            tList.AddRange(args);

            object result =null;
            var sucess = false;
            var exceptionList = new List<Exception>();

            var tGenericPossibles = new List<Type[]>();
            if (name.GenericArgs != null && name.GenericArgs.Length > 0)
            {
                var tInterface = CallTarget.GetType().GetInterfaces().Single(it => it.Name == _extendedType.Name);
                var tTypeGenerics = (tInterface.IsGenericType ? tInterface.GetGenericArguments()
                                            : new Type[] { }).Concat(name.GenericArgs).ToArray();

                tGenericPossibles.Add(tTypeGenerics);
                tGenericPossibles.Add(name.GenericArgs);
            }
            else
            {
                tGenericPossibles.Add(null);
            }

            foreach (var sType in _staticTypes)
            {
                foreach (var tGenericPossible in tGenericPossibles)
                {
                    try
                    {
                        result = Dynamic.InvokeMember(staticType(sType), nameArgs(name.Name, tGenericPossible), tList.ToArray());
                        sucess = true;
                        break;
                    }
                    catch (RuntimeBinderException ex)
                    {
                        exceptionList.Add(ex);
                    }
                }
            }

            if (!sucess)
            {
                throw exceptionList.First();
            }

            Type tOutType;
            if (TryTypeForName(name.Name, out tOutType))
            {
                if (tOutType.IsInterface)
                {
                    var tIsGeneric = tOutType.IsGenericType;
                    if (tOutType.IsGenericType)
                    {
                        tOutType = tOutType.GetGenericTypeDefinition();
                    }

                    if (InstanceHints.Select(it => tIsGeneric && it.IsGenericType ? it.GetGenericTypeDefinition() : it)
                            .Contains(tOutType))
                    {
                        result = CreateSelf(result, _extendedType, _staticTypes, _instanceHints);
                    }
                }
            }
            else
            {
                if (IsExtendedType(result))
                {
                    result = CreateSelf(result, _extendedType, _staticTypes, _instanceHints);
                }
            }

            return result;
        }
예제 #19
0
 public static BinderHash Create(Type delType, String_OR_InvokeMemberName name, Type context, string[] argNames, Type binderType, bool staticContext, bool isEvent, bool knownBinder)
 {
     return new BinderHash(delType, name, context, argNames, binderType, staticContext, isEvent, knownBinder);
 }
예제 #20
0
 protected GenericBinderHashBase(Type delegateType, String_OR_InvokeMemberName name, Type context, string[] argNames, Type binderType, bool staticContext, bool isEvent, bool knownBinder)
     : base(delegateType, name, context, argNames, binderType, staticContext, isEvent, knownBinder)
 {
 }
예제 #21
0
        /// <summary>
        /// Invokes the static method.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="args">The args.</param>
        /// <returns></returns>
        protected object InvokeStaticMethod(String_OR_InvokeMemberName name, object[] args)
        {
            var staticType = InvokeContext.CreateStatic;
            var nameArgs   = InvokeMemberName.Create;

            var tList = new List <object> {
                UnwrappedTarget()
            };

            tList.AddRange(args);

            object result        = null;
            var    sucess        = false;
            var    exceptionList = new List <Exception>();

            var tGenericPossibles = new List <Type[]>();

            if (name.GenericArgs != null && name.GenericArgs.Length > 0)
            {
                var tInterface    = UnwrappedTarget().GetType().GetTypeInfo().GetInterfaces().Single(it => it.Name == _extendedType.Name);
                var tTypeGenerics = (tInterface.GetTypeInfo().IsGenericType ? tInterface.GetTypeInfo().GetGenericArguments()
                                            : new Type[] { }).Concat(name.GenericArgs).ToArray();

                tGenericPossibles.Add(tTypeGenerics);
                tGenericPossibles.Add(name.GenericArgs);
            }
            else
            {
                tGenericPossibles.Add(null);
            }



            foreach (var sType in _staticTypes)
            {
                foreach (var tGenericPossible in tGenericPossibles)
                {
                    try
                    {
                        result = Dynamic.InvokeMember(staticType(sType), nameArgs(name.Name, tGenericPossible), tList.ToArray());
                        sucess = true;
                        break;
                    }
                    catch (RuntimeBinderException ex)
                    {
                        exceptionList.Add(ex);
                    }
                }
                if (sucess)
                {
                    break;
                }
            }

            if (!sucess)
            {
                throw exceptionList.First();
            }


            Type tOutType;

            if (TryTypeForName(name.Name, out tOutType))
            {
                var outTypeInfo = tOutType.GetTypeInfo();
                if (outTypeInfo.IsInterface)
                {
                    var tIsGeneric = outTypeInfo.IsGenericType;
                    if (outTypeInfo.IsGenericType)
                    {
                        tOutType = tOutType.GetGenericTypeDefinition();
                    }

                    if (InstanceHints.Select(it => tIsGeneric && it.GetTypeInfo().IsGenericType ? it.GetGenericTypeDefinition() : it)
                        .Any(it => it.Name == tOutType.Name))
                    {
                        result = CreateSelf(result, _extendedType, _staticTypes, _instanceHints);
                    }
                }
            }
            else
            {
                if (IsExtendedType(result))
                {
                    result = CreateSelf(result, _extendedType, _staticTypes, _instanceHints);
                }
            }

            return(result);
        }
예제 #22
0
파일: BinderHash.cs 프로젝트: caoxk/coapp
 public static BinderHash Create(Type delType, String_OR_InvokeMemberName name, Type context, string[] argNames, Type binderType, bool staticContext, bool isEvent)
 {
     return(new BinderHash(delType, name, context, argNames, binderType, staticContext, isEvent));
 }
예제 #23
0
 /// <summary>
 ///   Creates the invocation.
 /// </summary>
 /// <param name="kind"> The kind. </param>
 /// <param name="name"> The name. </param>
 /// <param name="storedArgs"> The args. </param>
 /// <returns> </returns>
 public static Invocation Create(InvocationKind kind, String_OR_InvokeMemberName name, params object[] storedArgs)
 {
     return new Invocation(kind, name, storedArgs);
 }
예제 #24
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="CacheableInvocation" /> class.
        /// </summary>
        /// <param name="kind"> The kind. </param>
        /// <param name="name"> The name. </param>
        /// <param name="argCount"> The arg count. </param>
        /// <param name="argNames"> The arg names. </param>
        /// <param name="context"> The context. </param>
        /// <param name="convertType"> Type of the convert. </param>
        /// <param name="convertExplict"> if set to <c>true</c> [convert explict]. </param>
        /// <param name="storedArgs"> The stored args. </param>
        public CacheableInvocation(InvocationKind kind,
            String_OR_InvokeMemberName name = null,
            int argCount = 0,
            string[] argNames = null,
            object context = null,
            Type convertType = null,
            bool convertExplict = false,
            object[] storedArgs = null)
            : base(kind, name, storedArgs)
        {
            _convertType = convertType;
            _convertExplict = convertExplict;

            _argNames = argNames ?? new string[] {};

            if (storedArgs != null) {
                _argCount = storedArgs.Length;
                string[] tArgNames;
                Args = Util.GetArgsAndNames(storedArgs, out tArgNames);
                if (_argNames.Length < tArgNames.Length) {
                    _argNames = tArgNames;
                }
            }

            switch (kind) //Set required argcount values
            {
                case InvocationKind.GetIndex:
                    if (argCount < 1) {
                        throw new ArgumentException("Arg Count must be at least 1 for a GetIndex", "argCount");
                    }
                    _argCount = argCount;
                    break;
                case InvocationKind.SetIndex:
                    if (argCount < 2) {
                        throw new ArgumentException("Arg Count Must be at least 2 for a SetIndex", "argCount");
                    }
                    _argCount = argCount;
                    break;
                case InvocationKind.Convert:
                    _argCount = 0;
                    if (convertType == null) {
                        throw new ArgumentNullException("convertType", " Convert Requires Convert Type ");
                    }
                    break;
                case InvocationKind.SubtractAssign:
                case InvocationKind.AddAssign:
                case InvocationKind.Set:
                    _argCount = 1;
                    break;
                case InvocationKind.Get:
                case InvocationKind.IsEvent:
                    _argCount = 0;
                    break;
                default:
                    _argCount = Math.Max(argCount, _argNames.Length);
                    break;
            }

            if (_argCount > 0) //setup argname array
            {
                var tBlank = new string[_argCount];
                if (_argNames.Length != 0) {
                    Array.Copy(_argNames, 0, tBlank, tBlank.Length - _argNames.Length, tBlank.Length);
                } else {
                    tBlank = null;
                }
                _argNames = tBlank;
            }

            if (context != null) {
            #pragma warning disable 168
                var tDummy = context.GetTargetContext(out _context, out _staticContext);
            #pragma warning restore 168
            } else {
                _context = typeof (object);
            }
        }
예제 #25
0
파일: BinderHash.cs 프로젝트: caoxk/coapp
 protected GenericBinderHashBase(Type delegateType, String_OR_InvokeMemberName name, Type context, string[] argNames, Type binderType, bool staticContext, bool isEvent)
     : base(delegateType, name, context, argNames, binderType, staticContext, isEvent)
 {
 }
예제 #26
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CacheableInvocation"/> class.
        /// </summary>
        /// <param name="kind">The kind.</param>
        /// <param name="name">The name.</param>
        /// <param name="argCount">The arg count.</param>
        /// <param name="argNames">The arg names.</param>
        /// <param name="context">The context.</param>
        /// <param name="convertType">Type of the convert.</param>
        /// <param name="convertExplicit">if set to <c>true</c> [convert explict].</param>
        /// <param name="storedArgs">The stored args.</param>
        public CacheableInvocation(InvocationKind kind,
                                   String_OR_InvokeMemberName name = null,
                                   int argCount         = 0,
                                   string[] argNames    = null,
                                   object context       = null,
                                   Type convertType     = null,
                                   bool convertExplicit = false,
                                   object[] storedArgs  = null)
            : base(kind, name, storedArgs)
        {
            _convertType     = convertType;
            _convertExplicit = convertExplicit;

            _argNames = argNames ?? new string[] {};

            if (storedArgs != null)
            {
                _argCount = storedArgs.Length;
                string[] tArgNames;
                Args = Util.GetArgsAndNames(storedArgs, out tArgNames);
                if (_argNames.Length < tArgNames.Length)
                {
                    _argNames = tArgNames;
                }
            }

            switch (kind) //Set required argcount values
            {
            case InvocationKind.GetIndex:
                if (argCount < 1)
                {
                    throw new ArgumentException("Arg Count must be at least 1 for a GetIndex", "argCount");
                }
                _argCount = argCount;
                break;

            case InvocationKind.SetIndex:
                if (argCount < 2)
                {
                    throw new ArgumentException("Arg Count Must be at least 2 for a SetIndex", "argCount");
                }
                _argCount = argCount;
                break;

            case InvocationKind.Convert:
                _argCount = 0;
                if (convertType == null)
                {
                    throw new ArgumentNullException("convertType", " Convert Requires Convert Type ");
                }
                break;

            case InvocationKind.SubtractAssign:
            case InvocationKind.AddAssign:
            case InvocationKind.Set:
                _argCount = 1;
                break;

            case InvocationKind.Get:
            case InvocationKind.IsEvent:
                _argCount = 0;
                break;

            default:
                _argCount = Math.Max(argCount, _argNames.Length);
                break;
            }

            if (_argCount > 0)//setup argname array
            {
                var tBlank = new string[_argCount];
                if (_argNames.Length != 0)
                {
                    Array.Copy(_argNames, 0, tBlank, tBlank.Length - _argNames.Length, tBlank.Length);
                }
                else
                {
                    tBlank = null;
                }
                _argNames = tBlank;
            }


            if (context != null)
            {
#pragma warning disable 168
                var tDummy = context.GetTargetContext(out _context, out _staticContext);
#pragma warning restore 168
            }
            else
            {
                _context = typeof(object);
            }
        }
예제 #27
0
        protected object InvokeStaticMethod(String_OR_InvokeMemberName name, object[] args)
        {
            var staticType = InvokeContext.CreateStatic;
            var nameArgs   = InvokeMemberName.Create;

            var tList = new List <object> {
                CallTarget
            };

            tList.AddRange(args);

            object result        = null;
            var    sucess        = false;
            var    exceptionList = new List <Exception>();

            var tGenericPossibles = new List <Type[]>();

            if (name.GenericArgs != null && name.GenericArgs.Length > 0)
            {
                var tInterface    = CallTarget.GetType().GetInterface(_extendedType.Name, false);
                var tTypeGenerics = (tInterface.IsGenericType ? tInterface.GetGenericArguments()
                                            : new Type[] { }).Concat(name.GenericArgs).ToArray();

                tGenericPossibles.Add(tTypeGenerics);
                tGenericPossibles.Add(name.GenericArgs);
            }
            else
            {
                tGenericPossibles.Add(null);
            }



            foreach (var sType in _staticTypes)
            {
                foreach (var tGenericPossible in tGenericPossibles)
                {
                    try
                    {
                        result = Impromptu.InvokeMember(staticType(sType), nameArgs(name.Name, tGenericPossible), tList.ToArray());
                        sucess = true;
                        break;
                    }
                    catch (RuntimeBinderException ex)
                    {
                        exceptionList.Add(ex);
                    }
                }
            }

            if (!sucess)
            {
#if SILVERLIGHT && !SILVERLIGHT5
                throw exceptionList.First();
#else
                throw new AggregateException(exceptionList);
#endif
            }


            Type tOutType;
            if (TryTypeForName(name.Name, out tOutType))
            {
                if (tOutType.IsInterface)
                {
                    var tIsGeneric = tOutType.IsGenericType;
                    if (tOutType.IsGenericType)
                    {
                        tOutType = tOutType.GetGenericTypeDefinition();
                    }

                    if (InstanceHints.Select(it => tIsGeneric && it.IsGenericType ? it.GetGenericTypeDefinition() : it)
                        .Contains(tOutType))
                    {
                        result = CreateSelf(result, _extendedType, _staticTypes, _instanceHints);
                    }
                }
            }
            else
            {
                if (IsExtendedType(result))
                {
                    result = CreateSelf(result, _extendedType, _staticTypes, _instanceHints);
                }
            }

            return(result);
        }