#region Arthea License
/***********************************************************************
*  Arthea MUD by R. Jennings (2007)      http://arthea.googlecode.com/ *
*  By using this code you comply with the Artistic and GPLv2 Licenses. *
***********************************************************************/
#endregion
using System.Collections.Generic;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
namespace Arthea.Continents.Areas.Items
{
    /// <summary>
    /// Implementation of a item index list.
    /// </summary>
    public class ItemIndexList : Dictionary<uint, ItemIndex>, IXmlSerializable
    {
        #region [rgn] Methods (3)
        // [rgn] Public Methods (3)
        /// <summary>
        /// Adds the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="index">The index.</param>
        public new void Add(uint id, ItemIndex index)
        {
            base.Add(index.Id, index);
        }
        /// <summary>
        /// Adds the specified index.
        /// </summary>
        /// <param name="index">The index.</param>
        public void Add(ItemIndex index)
        {
            base.Add(index.Id, index);
        }
        /// <summary>
        /// Removes the specified index.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns></returns>
        public bool Remove(ItemIndex index)
        {
            return Remove(index.Id);
        }
        #endregion [rgn]
        #region IXmlSerializable Members
        /// <summary>
        /// Converts an object into its XML representation.
        /// </summary>
        /// <param name="writer">The <see cref="T:System.Xml.XmlWriter"></see> stream to which the object is serialized.</param>
        public void WriteXml(XmlWriter writer)
        {
            if (Count == 0)
                return;
            foreach (ItemIndex item in Values)
            {
                Persistance.Save(writer, item);
            }
        }
        /// <summary>
        /// Generates an object from its XML representation.
        /// </summary>
        /// <param name="reader">The <see cref="T:System.Xml.XmlReader"></see> stream from which the object is deserialized.</param>
        public void ReadXml(XmlReader reader)
        {
            if (reader.IsEmptyElement)
                return;
            reader.ReadStartElement();
            while (reader.IsStartElement())
            {
                Add(Persistance.Load<ItemIndex>(reader));
            }
            reader.ReadEndElement();
        }
        /// <summary>
        /// This property is reserved, apply the <see cref="T:System.Xml.Serialization.XmlSchemaProviderAttribute"></see> to the class instead.
        /// </summary>
        /// <returns>
        /// An <see cref="T:System.Xml.Schema.XmlSchema"></see> that describes the XML representation of the object that is produced by the <see cref="M:System.Xml.Serialization.IXmlSerializable.WriteXml(System.Xml.XmlWriter)"></see> method and consumed by the <see cref="M:System.Xml.Serialization.IXmlSerializable.ReadXml(System.Xml.XmlReader)"></see> method.
        /// </returns>
        public XmlSchema GetSchema()
        {
            return (null);
        }
        #endregion
    }
}