using System;

namespace SharpQuake
{
	internal class DisposableWrapper<T> : IDisposable where T : class, IDisposable
	{
		public T Object
		{
			get
			{
				return this._Object;
			}
		}

		private void Dispose(bool disposing)
		{
			if (this._Object != null && this._Owned)
			{
				this._Object.Dispose();
				this._Object = default(T);
			}
		}

		public DisposableWrapper(T obj, bool dispose)
		{
			this._Object = obj;
			this._Owned = dispose;
		}

		~DisposableWrapper()
		{
			this.Dispose(false);
		}

		public void Dispose()
		{
			this.Dispose(true);
			GC.SuppressFinalize(this);
		}

		private T _Object;

		private bool _Owned;
	}
}
