using System; using System.Collections.Generic; namespace AspClassic.Parser; /// /// A parse tree for an If block. /// public sealed class IfBlockStatement : BlockStatement { private readonly Expression _Expression; private readonly Location _ThenLocation; private readonly StatementCollection _ElseIfBlockStatements; private readonly ElseBlockStatement _ElseBlockStatement; private readonly EndBlockStatement _EndStatement; /// /// The conditional expression. /// public Expression Expression => _Expression; /// /// The location of the 'Then', if any. /// public Location ThenLocation => _ThenLocation; /// /// The Else If statements. /// public StatementCollection ElseIfBlockStatements => _ElseIfBlockStatements; /// /// The Else statement, if any. /// public ElseBlockStatement ElseBlockStatement => _ElseBlockStatement; /// /// The End If statement, if any. /// public EndBlockStatement EndStatement => _EndStatement; /// /// Constructs a new parse tree for a If statement. /// /// The conditional expression. /// The location of the 'Then', if any. /// The statements in the If block. /// The Else If statements. /// The Else statement, if any. /// The End If statement, if any. /// The location of the parse tree. /// The comments for the parse tree. public IfBlockStatement(Expression expression, Location thenLocation, StatementCollection statements, StatementCollection elseIfBlockStatements, ElseBlockStatement elseBlockStatement, EndBlockStatement endStatement, Span span, IList comments) : base(TreeType.IfBlockStatement, statements, span, comments) { if (expression == null) { throw new ArgumentNullException("expression"); } SetParent(expression); SetParent(elseIfBlockStatements); SetParent(elseBlockStatement); SetParent(endStatement); _Expression = expression; _ThenLocation = thenLocation; _ElseIfBlockStatements = elseIfBlockStatements; _ElseBlockStatement = elseBlockStatement; _EndStatement = endStatement; } protected override void GetChildTrees(IList childList) { Tree.AddChild(childList, Expression); base.GetChildTrees(childList); Tree.AddChild(childList, ElseIfBlockStatements); Tree.AddChild(childList, ElseBlockStatement); Tree.AddChild(childList, EndStatement); } }