Hman,
You should be able to serialize instances like this:
PageList pl = new PageList();
// populate pl
XmlSerializer ser = new XmlSerializer( typeof( PageList ), new Type[] {
... } ); // enumerate all the types in the list.
ser.Serialize( writer, pl );
be careful though ... if you don't know what the types in your List are,
then getting the Types from the list elements and instantiating a serializer
instance is a very expensive operation and if performance matters, then you
should probably alter your design to not go that route.
I also have a few questions about the PageList class. Why do you implement
everything by hand, is there any reason you don't derive from CollectionBase
or ? And why are you even implementing a custom List if you don't strongly
type it? You may just as well stick to the ArrayList.
--
HTH
Christoph Schittko [MVP, XmlInsider]
Software Architect, .NET Mentor
"hman" <an*******@disc ussions.microso ft.com> wrote in message
news:08******** *************** *****@phx.gbl.. .
Hi,
I have a collection class where I've implemeneted the
ICollection Interface.
Here is a small code segment.
public class PageList : ICollection, IComparer,
IEnumerable, IList
{
protected ArrayList _pages;
public PageList()
{
_pages = new ArrayList();
}
#region IList Members
public object this[int index]
{
get
{
if (index > _pages.Count)
{
return (Page)null;
}
else
{
return (Page)_pages
[index];
}
}
set
{
}
}
public int Add(object objPage)
{
int arrayIndexAdded = -1;
arrayIndexAdded = _pages.Add
(objPage);
return arrayIndexAdded ;
}
}
I have another class which declares this PageList class
and creates an instance of it.
How do I serialized this class?