Statement() public static méthode

public static Statement ( Expression body, bool isEscaped, bool trimBefore, bool trimAfter ) : HandlebarsDotNet.Compiler.StatementExpression
body System.Linq.Expressions.Expression
isEscaped bool
trimBefore bool
trimAfter bool
Résultat HandlebarsDotNet.Compiler.StatementExpression
Exemple #1
0
        public override Expression GetAccumulatedBlock()
        {
            if (_accumulatedBody == null)
            {
                _accumulatedBody      = GetBlockBody();
                _accumulatedInversion = Expression.Block(Expression.Empty());
            }
            else if (_accumulatedInversion == null)
            {
                _accumulatedInversion = GetBlockBody();
            }

            var resultExpr = HandlebarsExpression.BlockHelper(
                _startingNode.HelperName,
                _startingNode.Arguments.Where(o => o.NodeType != (ExpressionType)HandlebarsExpressionType.BlockParamsExpression),
                _startingNode.Arguments.OfType <BlockParamsExpression>().SingleOrDefault() ?? BlockParamsExpression.Empty(),
                _accumulatedBody,
                _accumulatedInversion,
                _startingNode.IsRaw);

            if (_startingNode.IsRaw)
            {
                return(HandlebarsExpression.Statement(
                           resultExpr,
                           false,
                           _trimBefore,
                           _trimAfter));
            }

            return(resultExpr);
        }
Exemple #2
0
        public override Expression GetAccumulatedBlock()
        {
            if (_accumulatedBody == null)
            {
                _accumulatedBody      = GetBlockBody();
                _accumulatedInversion = Expression.Block(Expression.Empty());
            }
            else if (_accumulatedInversion == null)
            {
                _accumulatedInversion = GetBlockBody();
            }

            var resultExpr = HandlebarsExpression.BlockHelper(
                _startingNode.HelperName,
                _startingNode.Arguments,
                _accumulatedBody,
                _accumulatedInversion,
                _startingNode.IsRaw);

            if (_startingNode.IsRaw)
            {
                return(HandlebarsExpression.Statement(
                           resultExpr,
                           false,
                           _trimBefore,
                           _trimAfter));
            }

            return(resultExpr);
        }
        protected virtual Expression VisitStatementExpression(StatementExpression sex)
        {
            Expression body = Visit(sex.Body);

            if (body != sex.Body)
            {
                return(HandlebarsExpression.Statement(body, sex.IsEscaped, sex.TrimBefore, sex.TrimAfter));
            }
            return(sex);
        }
        public override IEnumerable <object> ConvertTokens(IEnumerable <object> sequence)
        {
            var enumerator = sequence.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var item            = enumerator.Current;
                var startExpression = item as StartExpressionToken;

                if (startExpression == null)
                {
                    yield return(item);

                    continue;
                }

                var possibleBody = GetNext(enumerator);
                if (!(possibleBody is Expression))
                {
                    throw new HandlebarsCompilerException(String.Format("Token '{0}' could not be converted to an expression", possibleBody));
                }

                var endExpression = GetNext(enumerator) as EndExpressionToken;
                if (endExpression == null)
                {
                    throw new HandlebarsCompilerException("Handlebars statement was not reduced to a single expression");
                }

                if (endExpression.IsEscaped != startExpression.IsEscaped)
                {
                    throw new HandlebarsCompilerException("Starting and ending handlebars do not match");
                }

                yield return(HandlebarsExpression.Statement(
                                 (Expression)possibleBody,
                                 startExpression.IsEscaped,
                                 startExpression.TrimPreceedingWhitespace,
                                 endExpression.TrimTrailingWhitespace));
            }
        }
        public override IEnumerable <object> ConvertTokens(IEnumerable <object> sequence)
        {
            var enumerator = sequence.GetEnumerator();

            while (enumerator.MoveNext())
            {
                var item = enumerator.Current;
                if (item is StartExpressionToken)
                {
                    var startExpression = item as StartExpressionToken;
                    item = GetNext(enumerator);
                    if ((item is Expression) == false)
                    {
                        throw new HandlebarsCompilerException(
                                  string.Format("Token '{0}' could not be converted to an expression", item));
                    }
                    yield return(HandlebarsExpression.Statement(
                                     (Expression)item,
                                     startExpression.IsEscaped));

                    item = GetNext(enumerator);
                    if ((item is EndExpressionToken) == false)
                    {
                        throw new HandlebarsCompilerException("Handlebars statement was not reduced to a single expression");
                    }
                    if (((EndExpressionToken)item).IsEscaped != startExpression.IsEscaped)
                    {
                        throw new HandlebarsCompilerException("Starting and ending handleabars do not match");
                    }
                }
                else
                {
                    yield return(item);
                }
            }
        }