Colin,
You can use the XmlSerializer class. Take note of this (from the help file):
"The XmlSerializer gives special treatment to classes that implement
IEnumerable or ICollection. A class that implements IEnumerable must
implement a public Add method that takes a single parameter. The Add
method's parameter must be of the same type as is returned from the Current
property on the value returned from GetEnumerator, or one of that type's
bases. A class that implements ICollection (such as CollectionBase) in
addition to IEnumerable must have a public Item indexed property (indexer in
C#) that takes an integer, and it must have a public Count property of type
integer. The parameter to the Add method must be the same type as is
returned from the Item property, or one of that type's bases. For classes
implementing ICollection, values to be serialized will be retrieved from the
indexed Item property, not by calling GetEnumerator."
If you follow the above it will know what Type your collection contains.
Here is an example:
using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
// ...
string path = Application.StartupPath + @"\\Serialization.xml";
// Write the output to disk
StreamWriter sr = new StreamWriter(path, false, System.Text.Encoding.UTF8);
XmlTextWriter writer = new XmlTextWriter(sr);
XmlSerializer serializer = new XmlSerializer(typeof(MyUserCollection));
MyUserCollection users = new MyUserCollection();
users.Add(new User("Suzie"));
users.Add(new User("Jacob"));
serializer.Serialize(sr, users);
sr.Close();
// Deserialize
StreamReader xmltext = new StreamReader(path, true);
MyUserCollection usersDeserialized =
(MyUserCollection)serializer.Deserialize(xmltext);
--
Ross Donald
Rad Software
Free Regular Expression Designer @
http://www.radsoftware.com.au/web/Products/
"Colin Basterfield" <co**************@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
| Hi,
|
| I have a list which is derived from CollectionBase, and it contains a list
| of User objects, which I want to Serialize out to an XML file.
|
| Is there anywhere where I can find how to decode it so that it recognizes
| what objects are held in my list? or an example in C# prefereably?
|
| Many thanks in advance...
| Colin
|
|
|