using System; using System.Collections.Generic; using System.Text; namespace TestIOC { public struct DisposableAction : IDisposable { public delegate void VoidFunc(); private VoidFunc mGuardFunction; public DisposableAction(VoidFunc guardFunction) { this.mGuardFunction = guardFunction; } /// /// This function remove the guard callback, is to be used with great attenction /// by the caller, but is a way to avoid disposable action to be called at the /// end of the scope. Remember that inside a using block there is no good way /// to avoid Dispose to be called. /// public void Dismiss() { mGuardFunction = null; } #region IDisposable Members void IDisposable.Dispose() { if (mGuardFunction != null) mGuardFunction(); } #endregion } }