Click here to Skip to main content
15,884,986 members
Articles / Web Development / HTML

XML Data Files, XML Serialization, and .NET

Rate me:
Please Sign up or sign in to vote.
4.82/5 (28 votes)
27 Aug 200317 min read 338.9K   6.4K   130  
Describes a means to build XML data files using XML Schema and xsd.exe to facilitate easy XML Serialization
using System;
using System.Collections;

namespace CardfileCE
{
	/// <summary>
	/// Summary description for CardCollection.
	/// </summary>
	public class CardCollection : CollectionBase
	{
		public CardCollection()
		{
		}

		public CardCollection(CardType[] arr)
		{
			AddRange(arr);
		}

		public CardCollection(CardCollection rhs)
		{
			if ( rhs != null )
			{
				foreach ( CardType item in InnerList )
				{
					Add(item);
				} // foreach
			} // if
		}

		/// <summary>
		public CardType this[int index]
		{
			get { return (CardType) InnerList[index]; }
		}

		public void Add(CardType item)
		{
			InnerList.Add(item);
		}

		public void AddRange(CardType[] items)
		{
			InnerList.AddRange(items);
		}

		public void Remove(CardType item)
		{
			InnerList.Remove(item);
		}

		public int IndexOf(CardType item)
		{
			return InnerList.IndexOf(item);
		}

		public void Insert(int index, CardType item)
		{
			InnerList.Insert(index, item);
		}

		public CardType FindByID(Int32 id)
		{
			// Find the card
			CardType card = null;
			try
			{
				foreach ( CardType item in InnerList )
				{
					if ( item.Header.ID == id ) card = item;
				} // foreach
			} // try
			catch (Exception)
			{
				// Blow it off and return a null card reference...
			} // catch

			return card; // may not be null
		}

		public CardType[] ToArray()
		{
			return (CardType[])InnerList.ToArray(typeof(CardType));
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions