using System;
namespace Wayne.Lib
{
///
/// 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.
///
public class ActionDisposable : DisposableBase
{
private readonly Action action;
///
/// Constructor.
///
/// Action to be invoked first time the object is disposed.
public ActionDisposable(Action action)
{
this.action = action;
}
protected override void DoDispose()
{
action();
}
}
}