12345678910111213141516171819202122232425262728 |
- using System;
- namespace Wayne.Lib
- {
- /// <summary>
- /// A disposable where a behavior can be invoked when dispose occurs.
- /// The dispose action will only be invoked once regardless number of times
- /// the Dispose method is called.
- /// </summary>
- public class ActionDisposable : DisposableBase
- {
- private readonly Action action;
- /// <summary>
- /// Constructor.
- /// </summary>
- /// <param name="action">Action to be invoked first time the object is disposed.</param>
- public ActionDisposable(Action action)
- {
- this.action = action;
- }
- protected override void DoDispose()
- {
- action();
- }
- }
- }
|