/// <summary> /// Simplify nested 'try { try {} catch {} } finally {}'. /// This transformation must run after the using/lock tranformations. /// </summary> TryCatchStatement TransformTryCatchFinally(TryCatchStatement tryFinally) { if (tryCatchFinallyPattern.IsMatch(tryFinally)) { TryCatchStatement tryCatch = (TryCatchStatement)tryFinally.TryBlock.Statements.Single(); tryFinally.TryBlock = tryCatch.TryBlock.Detach(); tryCatch.CatchClauses.MoveTo(tryFinally.CatchClauses); } // Since the tryFinally instance is not changed, we can continue in the visitor as usual, so return null return(null); }
public void TestEmptyFinallyDoesNotMatchNullFinally() { TryCatchStatement c1 = new TryCatchStatement { TryBlock = new BlockStatement(), CatchClauses = { new CatchClause { Body = new BlockStatement() } } }; TryCatchStatement c2 = new TryCatchStatement { TryBlock = new BlockStatement(), CatchClauses = { new CatchClause { Body = new BlockStatement() } }, FinallyBlock = new BlockStatement() }; Assert.IsFalse(c1.IsMatch(c2)); Assert.IsFalse(c2.IsMatch(c1)); // and vice versa }