예제 #1
0
        protected virtual E.CallExpression TranslateInvocationExpression(InvocationExpression invocationExpression, ILTranslationContext data)
        {
            var inv = new E.CallExpression();

            var mre = invocationExpression.Target as MemberReferenceExpression;

            if (mre != null)
            {
                // TODO: method mapping

                foreach (var t in mre.TypeArguments)
                {
                    inv.TypeArguments.Add(ResolveType(mre, t));
                }

                inv.Target = new E.PropertyExpression()
                {
                    Object   = GetExpression(mre.Target, data),
                    Property = mre.MemberName
                };
            }
            else
            {
                inv.Target = GetExpression(invocationExpression.Target, data);
            }

            foreach (var p in invocationExpression.Arguments)
            {
                inv.Parameters.Add(GetExpression(p, data));
            }

            return(inv);
        }
예제 #2
0
        protected virtual Expression TranslateInvocationExpression(E.CallExpression callExpression)
        {
            var f = new E.FunctionExpression();

            var l = new S.VariableDeclaration();

            l.Type = S.VariableDeclarationType.Let;
            l.Bindings.Add(new S.VariableBinding()
            {
                Variable = new E.IdentifierExpression("h")
            });

            f.Statements.Add(l);

            var ifb = new S.IfStatement();

            ifb.Condition = callExpression.Target;

            var inner = new S.IfStatement();

            inner.Condition = callExpression.Target.IsArray();

            inner.TruePart.Add(
                callExpression.Target.Property("forEach").Call(
                    new E.ArrowFunctionExpression(
                        new D.Parameter("e"),
                        new E.IdentifierExpression("h").AssignedBy(new E.IdentifierExpression("e").Call(callExpression.Parameters))
                        )
                    )
                );

            inner.TruePart.Add(new E.IdentifierExpression("h").ToReturn());

            inner.FalsePart.Add(callExpression.ToReturn());

            ifb.TruePart.Add(inner);
            f.Statements.Add(ifb);

            return(f.Call());
        }