using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace Howest.SchemaDiscovery.Configuration
{
	public abstract class SchemaDiscoveryEnhancedConfigurationElementCollection<TConfigurationElement> : SchemaDiscoveryConfigurationElementCollection<TConfigurationElement> where TConfigurationElement : ConfigurationElement, new()
	{
		internal SchemaDiscoveryEnhancedConfigurationElementCollection(string elementName)
			: base(ConfigurationElementCollectionType.AddRemoveClearMap, elementName)
		{
			base.AddElementName = elementName;
		}


		protected override void BaseAdd(ConfigurationElement element)
		{
			if (element == null)
			{
				throw new ArgumentNullException("element");
			}
			object key = this.GetElementKey(element);
			if (this.ContainsKey(key))
			{
				ConfigurationElement element2 = base.BaseGet(key);
				if (element2 != null)
				{
					if (element2.ElementInformation.IsPresent)
					{
						// TODO: add error description
						throw new ConfigurationErrorsException("");
					}
				}
			}
			base.BaseAdd(element);
		}

		protected override bool ThrowOnDuplicate
		{
			get
			{
				return false;
			}
		}
	}
}
