/// <summary>
        /// Evaluates the each loop
        /// </summary>
        /// <param name="context">The context that contains information about the document being rendered</param>
        /// <returns>The rendered contents of the each loop</returns>
        public ConsoleString Evaluate(DocumentRendererContext context)
        {
            var collection = context.EvaluateExpression(this.CollectionVariableExpressionToken.Value);

            if (collection == null)
            {
                throw new DocumentRenderException("'" + this.CollectionVariableExpressionToken.Value + "' resolved to a null reference", this.CollectionVariableExpressionToken);
            }

            if (collection is IEnumerable == false)
            {
                throw new DocumentRenderException("'" + this.CollectionVariableExpressionToken.Value + "' does not resolve to a collection", this.CollectionVariableExpressionToken);
            }
            ConsoleString ret   = ConsoleString.Empty;
            int           index = 0;
            var           iterationVariableName = this.IterationVariableNameToken.Value + "-index";

            foreach (var item in (IEnumerable)collection)
            {
                context.LocalVariables.Add(this.IterationVariableNameToken, item);
                context.LocalVariables.Force(iterationVariableName, index);
                ret += context.RenderBody(this.Body);
                context.LocalVariables.Remove(this.IterationVariableNameToken);
                context.LocalVariables.ForceClear(iterationVariableName);
                index++;
            }
            return(ret);
        }
Example #2
0
        /// <summary>
        /// Evaluates the each loop
        /// </summary>
        /// <param name="context">The context that contains information about the document being rendered</param>
        /// <returns>The rendered contents of the each loop</returns>
        public ConsoleString Evaluate(DocumentRendererContext context)
        {
            var collection = context.EvaluateExpression(this.CollectionVariableExpressionToken.Value);
            if (collection == null)
            {
                throw new DocumentRenderException("'" + this.CollectionVariableExpressionToken.Value + "' resolved to a null reference", this.CollectionVariableExpressionToken);
            }

            if(collection is IEnumerable == false)
            {
                throw new DocumentRenderException("'" + this.CollectionVariableExpressionToken.Value + "' does not resolve to a collection", this.CollectionVariableExpressionToken);
            }
            ConsoleString ret = ConsoleString.Empty;
            int index = 0;
            var iterationVariableName = this.IterationVariableNameToken.Value + "-index";
            foreach(var item in (IEnumerable)collection)
            {
                context.LocalVariables.Add(this.IterationVariableNameToken, item);
                context.LocalVariables.Force(iterationVariableName, index);
                ret+= context.RenderBody(this.Body);
                context.LocalVariables.Remove(this.IterationVariableNameToken);
                context.LocalVariables.ForceClear(iterationVariableName);
                index++;
            }
            return ret;
        }
Example #3
0
 /// <summary>
 /// Evaluates the conditional expression against the given data context, rendering the body only if it is true.
 /// </summary>
 /// <param name="context">The data context to use when evaluating the conditional expression</param>
 /// <returns>The rendered body if the conditional was true, an empty string otherwise</returns>
 public virtual ConsoleString Evaluate(DocumentRendererContext context)
 {
     var eval = context.EvaluateExpression(this.IfExpressionToken.Value);
     if(true.Equals(eval) || 1.Equals(eval))
     {
         return context.RenderBody(this.Body);
     }
     else
     {
         return ConsoleString.Empty;
     }
 }
        /// <summary>
        /// Evaluates the conditional expression against the given data context, rendering the body only if it is false.
        /// </summary>
        /// <param name="context">The data context to use when evaluating the conditional expression</param>
        /// <returns>The rendered body if the conditional was false, an empty string otherwise</returns>
        public override ConsoleString Evaluate(DocumentRendererContext context)
        {
            var eval = context.EvaluateExpression(this.IfExpressionToken.Value);

            if (false.Equals(eval) == true || 0.Equals(eval))
            {
                return(context.RenderBody(this.Body));
            }
            else
            {
                return(ConsoleString.Empty);
            }
        }
        /// <summary>
        /// Evaluates the conditional expression against the given data context, rendering the body only if it is true.
        /// </summary>
        /// <param name="context">The data context to use when evaluating the conditional expression</param>
        /// <returns>The rendered body if the conditional was true, an empty string otherwise</returns>
        public virtual ConsoleString Evaluate(DocumentRendererContext context)
        {
            var eval = context.EvaluateExpression(this.IfExpressionToken.Value);

            if (true.Equals(eval) || 1.Equals(eval))
            {
                return(context.RenderBody(this.Body));
            }
            else
            {
                return(ConsoleString.Empty);
            }
        }
Example #6
0
 /// <summary>
 /// Evaluates the conditional expression against the given data context, rendering the body only if it is false.
 /// </summary>
 /// <param name="context">The data context to use when evaluating the conditional expression</param>
 /// <returns>The rendered body if the conditional was false, an empty string otherwise</returns>
 public override ConsoleString Evaluate(DocumentRendererContext context)
 {
     var eval = context.EvaluateExpression(this.IfExpressionToken.Value);
     if (false.Equals(eval) == true || 0.Equals(eval))
     {
         return context.RenderBody(this.Body);
     }
     else
     {
         return ConsoleString.Empty;
     }
 }