Example #1
0
        /// <inheritdoc />
        protected override bool HandleDynamic(CodeLambdaDeclarationExpression obj, Context ctx)
        {
            ctx.Writer.Write("Function"); //it is safe to declare it as a function, but will give a warning
            ctx.Writer.Write("(");
            GeneralUtils.HandleCollectionCommaSeparated(obj.Parameters, ctx.HandlerProvider.ExpressionHandler, ctx);
            ctx.Writer.Write(")");
            if (obj.Statements.Count == 1 && obj.Statements[0] is CodeExpressionStatement statement)
            {
                ctx.Writer.Write(" ");
                VisualBasicUtils.BeginBlock(BlockType.Function, ctx, false);
                ctx.HandlerProvider.ExpressionHandler.Handle(statement.Expression, ctx);
                VisualBasicUtils.EndBlock(ctx, false, false);
            }
            else
            {
                ctx.Writer.NewLine();
                ctx.Indent();
                VisualBasicUtils.BeginBlock(BlockType.Function, ctx, false);
                VisualBasicUtils.HandleStatementCollection(obj.Statements, ctx);
                ctx.Unindent();
                ctx.Writer.Indent(ctx);
                VisualBasicUtils.EndBlock(ctx, false);
            }

            return(true);
        }
Example #2
0
        /// <inheritdoc />
        protected override bool HandleDynamic(CodeUnaryOperatorExpression obj, Context ctx)
        {
            string operatorSymbol = VisualBasicKeywordsUtils.UnaryOperatorSymbol(obj.Operator);

            if (operatorSymbol != null)
            {
                ctx.Writer.Write(operatorSymbol);
                WrapIfNecessaryAndHandle(obj.Expression, ctx);
                return(true);
            }

            if (obj.Operator == CodeUnaryOperatorType.PostDecrement ||
                obj.Operator == CodeUnaryOperatorType.PostIncrement ||
                obj.Operator == CodeUnaryOperatorType.PreDecrement ||
                obj.Operator == CodeUnaryOperatorType.PreIncrement)
            {
                //TODO this is ok when used as an expression, but not when used as a statement. Should be replaced with a method invocation, and add a library
                bool isIncrement = obj.Operator == CodeUnaryOperatorType.PostIncrement ||
                                   obj.Operator == CodeUnaryOperatorType.PreIncrement;
                bool isPre = obj.Operator == CodeUnaryOperatorType.PreDecrement ||
                             obj.Operator == CodeUnaryOperatorType.PreIncrement;

                CodeExpression toReturn;

                if (isPre)
                {
                    toReturn = obj.Expression;
                }
                else
                {
                    toReturn = new CodeBinaryOperatorExpressionMore(
                        obj.Expression,
                        isIncrement ? CodeBinaryOperatorTypeMore.Subtract : CodeBinaryOperatorTypeMore.Add,
                        Primitives.Int(1));
                }

                var lambda = new CodeLambdaDeclarationExpression(
                    new CodeCommentStatement(obj.Operator.ToString("G")),
                    new CodeOperationAssignmentStatement(
                        obj.Expression,
                        isIncrement ? CodeBinaryOperatorTypeMore.Add : CodeBinaryOperatorTypeMore.Subtract,
                        Primitives.Int(1)),
                    new CodeMethodReturnStatement(toReturn));
                ctx.HandlerProvider.ExpressionHandler.Handle(new CodeMethodInvokeExpression(lambda, "Invoke"), ctx);
                return(true);
            }
            return(false);
        }
Example #3
0
 /// <inheritdoc/>
 protected override bool HandleDynamic(CodeLambdaDeclarationExpression obj, Context ctx)
 {
     ctx.Writer.Write("(");
     GeneralUtils.HandleCollectionCommaSeparated(obj.Parameters, ctx.HandlerProvider.ExpressionHandler, ctx);
     ctx.Writer.Write(") =>");
     if (obj.Statements.Count == 1 && obj.Statements[0] is CodeExpressionStatement statement)
     {
         ctx.Writer.Write(" ");
         ctx.HandlerProvider.ExpressionHandler.Handle(statement.Expression, ctx);
     }
     else
     {
         ctx.Writer.NewLine();
         ctx.Writer.IndentAndWriteLine("{", ctx);
         ctx.Indent();
         CSharpUtils.HandleStatementCollection(obj.Statements, ctx, false);
         ctx.Unindent();
         ctx.Writer.IndentAndWrite("}", ctx);
     }
     return(true);
 }
 /// <inheritdoc cref="ICodeObjectHandler{T}.Handle"/>
 protected abstract bool HandleDynamic(CodeLambdaDeclarationExpression obj, Context ctx);