﻿using System;

namespace Gen2StreamPool
{
	public class PooledGen2Stream : Gen2Stream, IPooledObject
	{
		private IObjectPool objectPool;

		public PooledGen2Stream ()
		{
		}
			
		public PooledGen2Stream (int initialCount)
			:base(initialCount)
		{

		}
			
		public void Reset()
		{
			this.Position = 0;
		}

		public void SetObjectPool(IObjectPool objectPool)
		{
			this.objectPool = objectPool;
		}

		protected override void Dispose (bool disposing)
		{
			if (this.objectPool != null)
			{
				this.objectPool.Reclaim (this);
			}
			else
			{
				base.Dispose (disposing);
			}
		}
	}
}

