Re: Indexer Properties And WebServices -
03-05-2006
, 02:28 PM
The XmlSerializer can't serialize your classes indexer because it
doesn't know it's a collection (it doesn't implement ICollection). You
could probably implement ICollection (particularly easy in .NET 2.0
thanks to Generics, but I assume you're using .NET 1.x because you're
using ArrayList) but the easiest thing to do is change your class
slightly like so...
public class MyClass
{
private ArrayList _list = new ArrayList();
[XmlArray("MyList"), XmlArrayItem("Item", typeof(AnotherType))]
public ArrayList Items
{
get
{
return _list;
}
}
}
Which serializes to:
<MyClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MyList>
<Item>test1</Item>
<Item>test2</Item>
</MyList>
</MyClass>
If you're using .NET 2.0, give me a shout and I;ll send the generics
based example. Hope that helps.
Josh
http://www.thejoyofcode.com/ |