using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Common.Utilities { /// /// Calls the provided action when Disposed is called. Used to remove try/finally statments /// /// /// "Do something on Dispose()")) /// { /// //code here /// } /// ]]> /// public class DisposableAction : IDisposable { readonly Action _action; public DisposableAction(Action action) { _action = action; } public void Dispose() { _action(); } } }