Click here to Skip to main content
15,896,118 members
Articles / Desktop Programming / Windows Forms

Serialize and Deserialize IEnumerable Objects

Rate me:
Please Sign up or sign in to vote.
4.68/5 (29 votes)
11 Dec 2006CPOL10 min read 393.3K   2.4K   127  
CustomXmlSerializer is an alternative to XmlSerializer, supporting both shallow and deep serialization of ArrayLists, Collections, and Dictionaries.
using System;

namespace CSharp_CustomXmlSerializer_Demo
{
	public class Buyer:System.Xml.Serialization.IXmlSerializable
	{
		#region "Definition Section"
		private int _Identifier;
		private string _Name;
		private string _Email;
		private string _Phone;
		private Profile.Questionnaire _Questionnaire;
		#endregion

		#region "Exposed Properties"
		public int Identifier
		{
			get{return _Identifier;}
			set{_Identifier = value;}
		}


		public string Name
		{
			get{return _Name;}
			set{_Name = value;}
		}


		public string EMailAddress
		{
			get{return _Email;}
			set{_Email = value;}
		}


		public string PhoneNumber
		{
			get{return _Phone;}
			set{_Phone = value;}
		}


		public Profile.Questionnaire Questionnaire
		{
			get
			{
				if (_Questionnaire == null) _Questionnaire = new Profile.Questionnaire();
				return _Questionnaire;
			}
			set
			{
				_Questionnaire = value;
			}
		}


		public object PreferredPlans
		{get{return null;}}


		public object SelectedPlan
		{get{return null;}}
		#endregion

		#region "Implements IXmlSerializable"
		public System.Xml.Schema.XmlSchema GetSchema()
		{
			return null;
		}


		public void ReadXml(System.Xml.XmlReader reader)
		{
			CustomXmlSerializer XmlReader = new CustomXmlSerializer();
			XmlReader.ReadXml(reader, this);
		}


		public void WriteXml(System.Xml.XmlWriter writer)
		{
			CustomXmlSerializer XmlWriter = new CustomXmlSerializer();
			XmlWriter.WriteXml(this, writer);
		}
		#endregion
	}
}

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
Larry Steinle is a systems analyst for HDR, Inc, a nationally recognized architecture, engineering, and consulting firm. He graduated with a certificate in Biblical Studies, an Associate in Computer Programming, and a Bachelor Degree in Management Information Systems.

Comments and Discussions