public virtual ICodeContext CreateContext(CodeContextTypes contextType, string name, Bag <string> attributes = null) { if (this.Parent == null) { Context.Log(LogLevel.Error, $"{contextType} not supported in {Label} context", Context.Location.Line, Context.Location.Column); return(this); } else { return(this.Parent.CreateContext(contextType, name, attributes)); } }
public override ICodeContext CreateContext(CodeContextTypes contextType, string name = null, Bag <string> attributes = null) { switch (contextType) { case CodeContextTypes.Argument: return(new ExpressionContext((expression) => { if (expression == null) { _arguments.Add(SF.Argument(SF.LiteralExpression(SyntaxKind.NullLiteralExpression))); } else { var argumentExpression = expression.ToExpression(); #if never var parsedExpression = SF.ParseExpression(expression.ToString()); //Hack because the expression tree isn't being build the way Roslyn would like it #endif _arguments.Add(SF.Argument(argumentExpression)); } })); } return(base.CreateContext(contextType, name, attributes)); }
public override ICodeContext CreateContext(CodeContextTypes contextType, string name, Bag <string> attributes = null) { switch (contextType) { case CodeContextTypes.Attribute: return(new AttributeContext(name, (expression) => { _attributes.Add(new Attribute() { Name = name, Expression = expression.ToExpression() }); })); } return(base.CreateContext(contextType, name, attributes)); }
public override ICodeContext CreateContext(CodeContextTypes contextType, string name = null, Bag <string> attributes = null) { switch (contextType) { case CodeContextTypes.Argument: return(new ExpressionContext((expression) => { if (expression == null) { _testExpression = SF.LiteralExpression(SyntaxKind.FalseKeyword); } else { _testExpression = expression.ToExpression(); } })); } return(base.CreateContext(contextType, name, attributes)); }
public TagCloseContext(string tagName, Bag <string> attributes, ContentContextExitHandler <StatementSyntax> exitHandler) { _tagName = tagName; _exitHandler = exitHandler; }
public override ICodeContext CreateContext(CodeContextTypes contextType, string name = null, Bag <string> attributes = null) { switch (contextType) { case CodeContextTypes.MethodCall: return(new MethodCallContext(name, (methodCall) => { Add(OperatorTypes.Noop, methodCall); }, attributes?.Get <string>("hook"))); case CodeContextTypes.Expression: return(new ExpressionContext((expression) => { Add(_defaultOperator, expression); })); case CodeContextTypes.SignedExpression: return(new ExpressionContext((expression) => { Add(OperatorTypes.UnaryMinus, expression); })); case CodeContextTypes.ParenthesizedExpression: return(new ExpressionContext((expression) => { Add(_defaultOperator, new ExpressionNode(GetOperatorMap(OperatorTypes.Parenthesis), expression)); })); case CodeContextTypes.BinaryExpression: if (attributes?.Contains("operator") ?? false) { var operatorType = attributes.Get <OperatorTypes>("operator"); return(new ExpressionContext((expression) => { Add(operatorType, expression); })); } break; case CodeContextTypes.IndexExpression: bool last = attributes?.Get <bool>("last", false) ?? false; return(new ExpressionContext((expression) => { Add(last?OperatorTypes.LastIndex:OperatorTypes.Index, expression); })); case CodeContextTypes.OfExpression: bool lastOf = attributes?.Get <bool>("last", false) ?? false; return(new ExpressionContext((expression) => { Add(_defaultOperator, expression); }, lastOf? OperatorTypes.LastIndexOf:OperatorTypes.IndexOf)); } return(base.CreateContext(contextType, name, attributes)); }
public override ICodeContext CreateContext(CodeContextTypes contextType, string name = null, Bag <string> attributes = null) { switch (contextType) { case CodeContextTypes.Argument: return(new ExpressionContext((expression) => { if (expression == null) { _condition = SF.LiteralExpression(SyntaxKind.FalseKeyword); } else { _condition = expression.ToExpression(); } })); case CodeContextTypes.ElseIf: return(new IfContext(name, (ifStatement) => { _elseClause = SF.ElseClause(ifStatement); })); case CodeContextTypes.Else: string elseHookName = name; return(new BlockContext((block) => { if (elseHookName == null) { _elseClause = SF.ElseClause(block); } else { _elseClause = SF.ElseClause(BlockContext.MakeWriteStatement(MethodCallContext.CreateMethodCall(elseHookName, true))); } })); } return(base.CreateContext(contextType, name, attributes)); }