protected override Expression VisitChildren(ExpressionVisitor visitor) { //generate try block var tryBody = visitor.Visit(Wrap(Content.Body)); tryBody = tryBody.AddPrologue(false, prologue); if (!(finallyLabel is null)) { tryBody = tryBody.AddEpilogue(false, finallyLabel.Goto(), FaultLabel.LandingSite()); } //generate exception handlers block var handlers = new LinkedList <Expression>(); if (Content.Handlers.Count > 0) { handlers.AddLast(new ExitGuardedCodeExpression(previousState)); handlers.AddLast(new EnterGuardedCodeExpression(recoveryStateId)); foreach (var handler in Content.Handlers) { handlers.AddLast(visitor.Visit(new CatchStatement(handler, finallyLabel))); } } //generate finally block Expression fault = new FinallyStatement(Content.Finally ?? Content.Fault, previousState, finallyLabel ?? FaultLabel); fault = visitor.Visit(fault); return(tryBody.AddEpilogue(false, handlers).AddEpilogue(false, fault)); }
private Expression VisitAsyncResult(AsyncResultExpression expr) { if (context.IsInFinally) { throw new InvalidOperationException(ExceptionMessages.LeavingFinallyClause); } //attach all available finalization code var prologue = context.CurrentStatement.PrologueCodeInserter(); foreach (var finalization in context.CreateJumpPrologue(AsyncMethodEnd.Goto(), this)) { prologue(finalization); } return(expr); }