Abstract base class for nodes in hte syntax tree which evaluate expressions
Наследование: SyntaxTreeNode
Пример #1
0
 /// <summary>
 /// Evaluate whether the collectionExpression has Count > 0
 /// Can only be used on types that implement <see cref="System.Collections.ICollection"/>
 /// </summary>
 /// <param name="collectionExpression">An expression referencing a Collection</param>
 public static CollectionHasItemsExpressionNode HasItems(ExpressionNode collectionExpression)
 {
     return new CollectionHasItemsExpressionNode
     {
         CollectionExpression = collectionExpression,
         Scope = collectionExpression.Scope
     };
 }
Пример #2
0
 /// <summary>
 /// Execute another template in the scope of the provided model
 /// </summary>
 /// <param name="templateName">The name of the template to execute. It will be loaded from the <see cref="IVeilContext"/></param>
 /// <param name="modelExpression">An expression for the model to be used as the root scope when executing the template</param>
 public static IncludeTemplateNode Include(string templateName, ExpressionNode modelExpression)
 {
     return new IncludeTemplateNode
     {
         ModelExpression = modelExpression,
         TemplateName = templateName
     };
 }
Пример #3
0
 /// <summary>
 /// Iterate a collection and execute the body block scoped to each item in the collection.
 /// Optionally execute an empty block when there are no items to iterate
 /// </summary>
 /// <param name="collectionExpression">expression to load the collection</param>
 /// <param name="body">Block to execute in the scope of each item</param>
 /// <param name="emptyBody">Block to execute when there are no items in the collection</param>
 public static IterateNode Iterate(ExpressionNode collectionExpression, BlockNode body, BlockNode emptyBody = null)
 {
     return new IterateNode
     {
         Collection = collectionExpression,
         Body = body,
         EmptyBody = emptyBody ?? SyntaxTree.Block()
     };
 }
Пример #4
0
        /// <summary>
        /// Evaluate an expression and write the value to the TextWriter
        /// </summary>
        /// <param name="expression">The expression to be written</param>
        /// <param name="htmlEncode">Indicates whether the content should be html encoded before being written</param>
        public static WriteExpressionNode WriteExpression(ExpressionNode expression, SourceLocation location, bool htmlEncode = false)
        {
            return new WriteExpressionNode
            {
				Location = location,
                Expression = expression,
                HtmlEncode = htmlEncode
            };
        }
Пример #5
0
 /// <summary>
 /// Evaluates an expression and chooses between two blocks based on the truthy-ness of the result
 /// </summary>
 /// <param name="expression">The expression to evaluate</param>
 /// <param name="trueBlock">The block to execute when the expression is true</param>
 /// <param name="falseBlock">The block to evaluate when the expression is false</param>
 /// <returns></returns>
 public static ConditionalNode Conditional(ExpressionNode expression, BlockNode trueBlock, BlockNode falseBlock = null)
 {
     return new ConditionalNode
     {
         Expression = expression,
         TrueBlock = trueBlock,
         FalseBlock = falseBlock
     };
 }
		/// <summary>
		/// Evaluate an expression on a sub model, can be nested to traverse any depth of sub models
		/// </summary>
		/// <param name="modelExpression">An expression referencing the model to traverse to</param>
		/// <param name="subModelExpression">An expression to evaluate in the scope of the model that has been traversed to</param>
		/// <param name="scope">The scope this expression evaluated in</param>
		public static SubModelExpressionNode SubModel(ExpressionNode modelExpression, ExpressionNode subModelExpression, SourceLocation location, ExpressionScope scope = ExpressionScope.CurrentModelOnStack)
		{
			return new SubModelExpressionNode
			{
				Location = location,
				ModelExpression = modelExpression,
				SubModelExpression = subModelExpression,
				Scope = scope
			};
		}
Пример #7
0
 /// <summary>
 /// Evaluate an expression and write the value to the TextWriter
 /// </summary>
 /// <param name="expression">The expression to be written</param>
 /// <param name="htmlEncode">Indicates whether the content should be html encoded before being written</param>
 public static WriteExpressionNode WriteExpression(ExpressionNode expression, bool htmlEncode = false)
 {
     return new WriteExpressionNode
     {
         Expression = expression,
         HtmlEncode = htmlEncode
     };
 }
Пример #8
0
 /// <summary>
 /// Scopes a node to a new model
 /// </summary>
 /// <param name="modelToScopeTo">An expression that evaluates to the model to scope to</param>
 /// <param name="node">The node to execute in the new scope</param>
 public static ScopedNode ScopeNode(ExpressionNode modelToScopeTo, SyntaxTreeNode node)
 {
     return new ScopedNode
     {
         ModelToScope = modelToScopeTo,
         Node = node
     };
 }
		/// <summary>
		/// Evaluate whether the collectionExpression has Count > 0
		/// Can only be used on types that implement <see cref="System.Collections.ICollection"/>
		/// </summary>
		/// <param name="collectionExpression">An expression referencing a Collection</param>
		public static CollectionHasItemsExpressionNode HasItems(ExpressionNode collectionExpression, SourceLocation location)
		{
			return new CollectionHasItemsExpressionNode
			{
				Location = location,
				CollectionExpression = collectionExpression,
				Scope = collectionExpression.Scope
			};
		}
Пример #10
0
	    /// <summary>
	    /// Evaluate whether the collectionExpression has Count > 0
	    /// Can only be used on types that implement <see cref="System.Collections.ICollection"/>
	    /// </summary>
	    /// <param name="collectionExpression">An expression referencing a Collection</param>
	    /// <param name="location"></param>
	    /// <param name="recursionLevel"></param>
	    public static CollectionHasItemsExpressionNode HasItems(ExpressionNode collectionExpression, SourceLocation location, int recursionLevel = 0)
		{
			return new CollectionHasItemsExpressionNode
			{
				Location = location,
				CollectionExpression = collectionExpression,
				Scope = collectionExpression.Scope,
                RecursionLevel = recursionLevel
			};
		}
Пример #11
0
        /// <summary>
        /// Execute another template in the scope of the provided model
        /// </summary>
        /// <param name="templateName">The name of the template to execute. It will be loaded from the <see cref="IVeilContext"/></param>
        /// <param name="modelExpression">An expression for the model to be used as the root scope when executing the template</param>
        public static IncludeTemplateNode Include(string templateName, ExpressionNode modelExpression, SourceLocation location)
        {
            return new IncludeTemplateNode
            {
				Location = location,
                ModelExpression = modelExpression,
                TemplateName = templateName
            };
        }
Пример #12
0
        /// <summary>
        /// Scopes a node to a new model
        /// </summary>
        /// <param name="modelToScopeTo">An expression that evaluates to the model to scope to</param>
        /// <param name="node">The node to execute in the new scope</param>
        public static ScopedNode ScopeNode(ExpressionNode modelToScopeTo, SyntaxTreeNode node, SourceLocation location)
        {
            return new ScopedNode
            {
				Location = location,
                ModelToScope = modelToScopeTo,
                Node = node
            };
        }