Ejemplo n.º 1
0
        public static dynamic Invoke(object target, params object[] arguments)
        {
            string[] argumentNames;
            Type     context;
            bool     staticContext;

            target    = target.GetInvocationContext(out context, out staticContext);
            arguments = TypeFactorization.ExtractArgumentNamesAndValues(arguments, out argumentNames);
            CallSite theCallSite = null;

            return(InvocationMapping.InvokeDirectCallSite(target, arguments, argumentNames, context, staticContext,
                                                          ref theCallSite));
        }
Ejemplo n.º 2
0
        public override object Invoke(object target, params object[] args)
        {
            var invocationContext = target as InvocationContext;

            if (invocationContext != null)
            {
                target = invocationContext.Target;
            }

            if (args == null)
            {
                args = new object[] { null };
            }

            ValidateInvocationArguments(args);

            switch (Kind)
            {
            case InvocationKind.Constructor:
                var tTarget = (Type)target;
                return(InvocationMapping.InvokeConstructorCallSite(tTarget, tTarget.IsValueType, args,
                                                                   _argumentNames, _context,
                                                                   ref _callSite));

            case InvocationKind.Convert:
                return(InvocationMapping.InvokeConvertCallSite(target, _convertExplict, _convertType, _context,
                                                               ref _callSite));

            case InvocationKind.Get:
                return(InvocationMapping.InvokeGetCallSite(target, Name.Name, _context, _staticContext,
                                                           ref _callSite));

            case InvocationKind.Set:
                InvocationMapping.InvokeSetCallSite(target, Name.Name, args[0], _context, _staticContext,
                                                    ref _callSite);
                return(null);

            case InvocationKind.GetIndex:
                return(InvocationMapping.InvokeGetIndexCallSite(target, args, _argumentNames, _context,
                                                                _staticContext, ref _callSite));

            case InvocationKind.SetIndex:
                InvocationBinding.InvokeSetIndex(target, args);
                return(null);

            case InvocationKind.InvokeMember:
                return(InvocationMapping.InvokeMemberCallSite(target, Name, args, _argumentNames, _context,
                                                              _staticContext, ref _callSite));

            case InvocationKind.InvokeMemberAction:
                InvocationMapping.InvokeMemberActionCallSite(target, Name, args, _argumentNames, _context,
                                                             _staticContext, ref _callSite);
                return(null);

            case InvocationKind.InvokeMemberUnknown:
            {
                try
                {
                    var tObj = InvocationMapping.InvokeMemberCallSite(target, Name, args, _argumentNames,
                                                                      _context, _staticContext, ref _callSite);
                    return(tObj);
                }
                catch (RuntimeBinderException)
                {
                    InvocationMapping.InvokeMemberActionCallSite(target, Name, args, _argumentNames, _context,
                                                                 _staticContext, ref _callSite2);
                    return(null);
                }
            }

            case InvocationKind.Invoke:
                return(InvocationMapping.InvokeDirectCallSite(target, args, _argumentNames, _context, _staticContext,
                                                              ref _callSite));

            case InvocationKind.InvokeAction:
                InvocationMapping.InvokeDirectActionCallSite(target, args, _argumentNames, _context, _staticContext,
                                                             ref _callSite);
                return(null);

            case InvocationKind.InvokeUnknown:
            {
                try
                {
                    var tObj = InvocationMapping.InvokeDirectCallSite(target, args, _argumentNames, _context,
                                                                      _staticContext, ref _callSite);
                    return(tObj);
                }
                catch (RuntimeBinderException)
                {
                    InvocationMapping.InvokeDirectActionCallSite(target, args, _argumentNames, _context,
                                                                 _staticContext, ref _callSite2);
                    return(null);
                }
            }

            case InvocationKind.AddAssign:
                InvocationMapping.InvokeAddAssignCallSite(target, Name.Name, args, _argumentNames, _context,
                                                          _staticContext, ref _callSite, ref _callSite2,
                                                          ref _callSite3, ref _callSite4);
                return(null);

            case InvocationKind.SubtractAssign:
                InvocationMapping.InvokeSubtractAssignCallSite(target, Name.Name, args, _argumentNames, _context,
                                                               _staticContext, ref _callSite, ref _callSite2,
                                                               ref _callSite3, ref _callSite4);
                return(null);

            case InvocationKind.IsEvent:
                return(InvocationMapping.InvokeIsEventCallSite(target, Name.Name, _context, ref _callSite));

            default:
                throw new InvalidOperationException("Unknown Invocation Kind: " + Kind);
            }
        }