/ Published in: C#
[Serializable]
[XmlRoot("items")]
public class ItemCollection : XmlSerializableCollection
{
}
[XmlRoot("items")]
public class ItemCollection : XmlSerializableCollection
{
}
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/// <summary> /// <see cref="ICollection{T}"/> implementation which also provides xml serialization /// </summary> /// <typeparam name="T">The type of the contained elements</typeparam> public abstract class XmlSerializableCollection<T> : ICollection<T>, IXmlSerializable { #region Fields #endregion #region Properties /// <summary> /// Obtains / Sets the element in a given ordinal position /// </summary> /// <param name="index">The ordinal position</param> public T this[int index] { get { return items[index]; } set { items[index] = value; } } #endregion #region ICollection<T> Members public void Add( T item ) { items.Add( item ); } public void Clear() { items.Clear(); } public bool Contains( T item ) { return items.Contains( item ); } public void CopyTo( T[] array, int arrayIndex ) { items.CopyTo( array, arrayIndex ); } public int Count { get { return items.Count; } } public bool IsReadOnly { get { return items.IsReadOnly; } } public bool Remove( T item ) { return items.Remove( item ); } #endregion #region IEnumerable<T> Members public IEnumerator<T> GetEnumerator() { return items.GetEnumerator(); } #endregion #region IEnumerable Members IEnumerator IEnumerable.GetEnumerator() { return items.GetEnumerator(); } #endregion #region IXmlSerializable Members public virtual XmlSchema GetSchema() { return null; } public virtual void ReadXml( XmlReader reader ) { XmlSerializerHelper.DeserializeCollection( reader, items ); } public virtual void WriteXml( XmlWriter writer ) { XmlSerializerHelper.Serialize( writer, this ); } #endregion }