Example #1
0
        /// <summary>
        /// Attempts to bind to an operator Call method.
        /// </summary>
        private TargetInfo TryGetOperatorTargets(MetaObject self, MetaObject[] args, object target, CallSignature signature)
        {
            MethodBase[] targets;

            Type targetType = CompilerHelpers.GetType(target);

            MemberGroup       callMembers = GetMember(OldCallAction.Make(this, signature), targetType, "Call");
            List <MethodBase> callTargets = new List <MethodBase>();

            foreach (MemberTracker mi in callMembers)
            {
                if (mi.MemberType == TrackerTypes.Method)
                {
                    MethodInfo method = ((MethodTracker)mi).Method;
                    if (method.IsSpecialName)
                    {
                        callTargets.Add(method);
                    }
                }
            }

            Expression instance = null;

            if (callTargets.Count > 0)
            {
                targets  = callTargets.ToArray();
                instance = Ast.Convert(self.Expression, CompilerHelpers.GetType(target));
                return(new TargetInfo(null, ArrayUtils.Insert(self, args), targets));
            }

            return(null);
        }
        public override Expression Bind(object[] args, ReadOnlyCollection <ParameterExpression> parameters, LabelTarget returnLabel)
        {
            ContractUtils.RequiresNotNull(args, "args");
            CodeContext cc = ExtractCodeContext(ref args);

            ContractUtils.Requires(args.Length > 0);
            IOldDynamicObject ido = args[0] as IOldDynamicObject;

            ContractUtils.RequiresNotNull(ido, "args");

            OldCallAction ca      = OldCallAction.Make(cc.LanguageContext.Binder, _args);
            var           builder = new RuleBuilder(parameters, returnLabel);

            if (!ido.GetRule(ca, cc, args, builder))
            {
                throw new InvalidOperationException("Cannot perform call.");
            }

            return(builder.CreateRule());
        }