diff Implab/Disposable.cs @ 40:fe33f4e02ad5

improved tracing added text listeners (file,console)
author cin
date Tue, 15 Apr 2014 17:52:09 +0400
parents
children d9d794b61bb9
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Implab/Disposable.cs	Tue Apr 15 17:52:09 2014 +0400
@@ -0,0 +1,46 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Web;
+
+namespace Implab {
+    public class Disposable : IDisposable {
+        
+        bool m_disposed;
+
+        public event EventHandler Disposed;
+
+        public bool IsDisposed {
+            get { return m_disposed; }
+        }
+
+        protected void AssertNotDisposed() {
+            if (m_disposed)
+                throw new ObjectDisposedException(this.ToString());
+        }
+
+        protected virtual void Dispose(bool disposing) {
+            if (disposing && !m_disposed) {
+                m_disposed = true;
+                
+                EventHandler temp = Disposed;
+                if (temp != null) 
+                    temp(this,EventArgs.Empty);
+            }
+        }
+        public void Dispose() {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+
+        protected virtual void ReportObjectLeaks() {
+            Trace.TraceWarning("The object is marked as disposable but isn't disposed properly: {0}", this);
+        }
+
+        ~Disposable() {
+            Dispose(false);
+            ReportObjectLeaks();
+        }
+    }
+}
\ No newline at end of file