Undo - I invoke a third-party assembly that supports undo operations. This requires callers to create a cancellation context, call some methods in the assembly, and then destroy the cancellation context. Contexts can be nested. In addition, if the context is created, but remains in an undesirable state that requires a restart of the application.
Usually use undo, I would write something like this
void foo() { int id = lib.create_undo_context(); try { lib.performsomeaction(); lib.performsomeaction(); lib.performsomeaction(); } finally { lib.destroy_undo_context(id); } }
with PostSharp I define an attribute called [Undo] that creates a cancellation context when the method starts and destroys it when the method exits (even if an exception is thrown) - so the code looks like this:
[Undo] void foo() { lib.performsomeaction(); lib.performsomeaction(); lib.performsomeaction(); }
It's a little harder to implement this than I'm showing, because I'm sure all cancellation contexts are canceled even in cases where nested Undo contexts - but you get the idea.
namenlos Dec 20 '08 at 13:44 2008-12-20 13:44
source share