using System; namespace JD.Kernel.Classes { /// /// Simple class that implements NotFinalizable using a delegate. /// /// /// Can be useful to implement a "using pattern" that must absolutly be disposed explicitly without defining a nested class. /// /// /// /// public class MyClass /// { /// public IDisposable Start() /// { /// return new NotFinalizableHelper(delegate /// { /// // ... End code. /// }); /// } /// } /// /// using (MyClass.Start()) /// { /// ... /// } /// /// public class NotFinalizableHelper : NotFinalizable { #region Variables private readonly Action m_action; #endregion #region Constructors /// /// Constructor. /// /// public NotFinalizableHelper(Action action) { m_action = action; } /// /// Overriden. /// /// protected override void Dispose(bool disposing) { if (disposing && m_action != null) { m_action(); } base.Dispose(disposing); } #endregion } }