CharIndexList.cs

src/Continents/Areas/Characters/CharIndexList.cs · 3.4 KB

From the archive Arthea-src-1.0.zip

Download the archive   « Back to the archive contents

#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.Characters
{
    /// <summary>
    /// Implementation of a char index list.
    /// </summary>
    public class CharIndexList : Dictionary<uint, CharIndex>, 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, CharIndex index)
        {
            base.Add(index.Id, index);
        }

        /// <summary>
        /// Adds the specified index.
        /// </summary>
        /// <param name="index">The index.</param>
        public void Add(CharIndex index)
        {
            base.Add(index.Id, index);
        }

        /// <summary>
        /// Removes the specified index.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns>true if successful</returns>
        public bool Remove(CharIndex 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 (CharIndex ch in Values)
            {
                Persistance.Save(writer, ch);
            }
        }

        /// <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<CharIndex>(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
    }
}

Site Stats

Snippets: 1791
Codebases: 571