protected override Expression VisitTry(TryExpression node)
{
var res = default(Expression);
if (node.Finally != null || node.Fault != null)
{
var body = Visit(node.Body);
var handlers = Visit(node.Handlers, VisitCatchBlock);
if (node.Finally != null)
{
Debug.Assert(node.Fault == null);
var @finally = default(Expression);
if (VisitAndFindAwait(node.Finally, out @finally))
{
if (handlers.Count != 0)
{
body = Expression.TryCatch(body, handlers.ToArray());
}
res = RewriteHandler(body, @finally, isFault: false);
}
else
{
res = node.Update(body, handlers, @finally, null);
}
}
else
{
Debug.Assert(node.Finally == null);
var fault = default(Expression);
if (VisitAndFindAwait(node.Fault, out fault))
{
Debug.Assert(handlers.Count == 0);
res = RewriteHandler(body, fault, isFault: true);
}
else
{
res = node.Update(body, handlers, null, fault);
}
}
}
else
{
res = base.VisitTry(node);
}
return res;
}