Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Common.Utilities
- {
- /// <summary>
- /// Calls the provided action when Disposed is called. Used to remove try/finally statments
- /// </summary>
- /// <example>
- /// <![CDATA[
- /// using (new DisposableAction(() => "Do something on Dispose()"))
- /// {
- /// //code here
- /// }
- /// ]]>
- /// </example>
- public class DisposableAction : IDisposable
- {
- readonly Action _action;
- public DisposableAction(Action action)
- {
- _action = action;
- }
- public void Dispose()
- {
- _action();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment