1. // Higher level code die gebruik maakt van mijn TransactionContext
  2. using (TransactionContext tc = new TransactionContext() )
  3. {
  4. tc.setProperty("PROP1", "value1");
  5. tc.setProperty("PROP2", "value2");
  6. tc.setProperty("PROP3", "value3");
  7. throw UnexpectedException();
  8. tc.setProperty("PROP4", "value4");
  9. }
  10.  
  11. // Vertaling
  12. try
  13. {
  14. TransactionContext tc = new TransactionContext();
  15. tc.setProperty("PROP1", "value1");
  16. tc.setProperty("PROP2", "value2");
  17. tc.setProperty("PROP3", "value3");
  18. throw UnexpectedException();
  19. tc.setProperty("PROP4", "value4");
  20. }
  21. finally
  22. {
  23. tc.Dispose();
  24. }
  25.  
  26. // Wat ik dus zou moeten doen
  27. public class TransactionContext
  28. {
  29. public override void Dispose()
  30. {
  31. PushAllPropertyChangesToDB();
  32. }
  33. }
  34.  
  35. // Maar ik wil geen PushAllPropertyChanges als een exception gegooid werd in mijn try block