using System.Configuration;

namespace ChuPiao.AutoPrint.Configuration
{
    [ConfigurationCollection(typeof(TemplateElement))]
    public class TemplateCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new TemplateElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            TemplateElement e = element as TemplateElement;
            return e.Name;
        }

        public TemplateElement this[int index]
        {
            get
            {
                return (TemplateElement)BaseGet(index);
            }
        }

        public new TemplateElement this[string key]
        {
            get
            {
                foreach (TemplateElement e in this)
                {
                    if (e.Name == key)
                    {
                        return e;
                    }
                }
                return null;
            }
        }
    }
}
