public override AstNode VisitUsingStatement(UsingStatement usingStatement) { var awaitSearch = new AwaitSearchVisitor(null); usingStatement.AcceptVisitor(awaitSearch); var awaiters = awaitSearch.GetAwaitExpressions().ToArray(); UsingStatement node = (UsingStatement)base.VisitUsingStatement(usingStatement) ?? (UsingStatement)usingStatement.Clone(); if (awaiters.Length > 0) { IEnumerable <AstNode> inner = null; var res = node.ResourceAcquisition; var varStat = res as VariableDeclarationStatement; if (varStat != null) { inner = varStat.Variables.Skip(1); res = varStat.Variables.First(); } return(EmitUsing(node, res, inner, varStat)); } return(node); }
protected override void DoEmit() { if (ExpressionStatement.IsNull) { return; } var oldSemiColon = Emitter.EnableSemicolon; if (Emitter.IsAsync) { var awaitSearch = new AwaitSearchVisitor(Emitter); ExpressionStatement.Expression.AcceptVisitor(awaitSearch); } bool isAwaiter = ExpressionStatement.Expression is UnaryOperatorExpression && ((UnaryOperatorExpression)ExpressionStatement.Expression).Operator == UnaryOperatorType.Await; ExpressionStatement.Expression.AcceptVisitor(Emitter); if (Emitter.EnableSemicolon && !isAwaiter) { WriteSemiColon(true); } if (oldSemiColon) { Emitter.EnableSemicolon = true; } }
protected AstNode[] GetAwaiters(AstNode node) { var awaitSearch = new AwaitSearchVisitor(Emitter); node.AcceptVisitor(awaitSearch); return(awaitSearch.GetAwaitExpressions().ToArray()); }
public override void VisitUsingStatement(UsingStatement usingStatement) { if (Found) { return; } var awaitSearch = new AwaitSearchVisitor(null); usingStatement.AcceptVisitor(awaitSearch); var awaiters = awaitSearch.GetAwaitExpressions().ToArray(); if (awaiters.Length > 0) { Found = true; } base.VisitUsingStatement(usingStatement); }