private Action <IForAllItemExecutionContext <IDisposable> > CreateDisposeItemAction(bool disposing) { return(delegate(IForAllItemExecutionContext <IDisposable> ctx) { EventHandler <DisposeObjectEventArgs> eventHandler = this.DisposingObject; IDisposable obj = ctx.Item; DisposeObjectEventArgs e = new DisposeObjectEventArgs(obj, disposing); if (eventHandler != null) { eventHandler(this, e); } if (e.Cancel) { return; } try { if (e.IsDispoing == false) { return; } bool doDispose = true; ITMDisposable tmDisp = obj as ITMDisposable; if (tmDisp != null) { // only if disposed doDispose = tmDisp.IsDisposed == false; } if (doDispose) { obj.Dispose(); } } finally { this._OBJECTS .Remove(obj); } }); }
// Protected Methods (2) /// <inheriteddoc /> protected override void Dispose(bool disposing) { lock (this._SYNC) { base.Dispose(disposing); if (disposing) { IEnumerable <TextWriterEntry> entriesToDispose = CollectionHelper.Where(this._ENTRIES, delegate(TextWriterEntry entry) { return(entry.DISPOSE); }); CollectionHelper.ForAll(entriesToDispose, delegate(IForAllItemExecutionContext <TextWriterEntry> ctx) { TextWriter obj = ctx.Item.WRITER; bool doDispose = true; ITMDisposable tmDispObj = obj as ITMDisposable; if (tmDispObj != null) { doDispose = tmDispObj.IsDisposed == false; } if (doDispose) { obj.Dispose(); } }, true); } else { this._ENTRIES.Clear(); } } }