I've created the following two classes; one to represent the object I'm working with and another to act as a collection.
Public Class User
Private propUserName As String
Public Property UserName() As String
Get
Return propUserName
End Get
Set(ByVal value As String)
propUserName = value
End Set
End Property
End Class
and the second class to hold the user classes in a collection...
Partial Public Class UserCollection
Inherits ArrayList
Default Public Shadows Property Item(ByVal index As Integer) As User
Get
Return MyBase.Item(index)
End Get
Set(ByVal Item As User)
MyBase.Item(index) = Item
End Set
End Property
End Class
Serializing the user class on it's own produces an output I would expect;
But serializing the user collection class produces a problem. For some reason the XmlSerializer converts the element names into pascal case (first letter is a capital) instead of camel case (i.e. myBase) - meaning that I get an output like this;
<User username="value"/>
This causes a problem when I try to deserialize the xml string back into an object, as the XmlSerializer is expecting "user" not "User" (defined in both classes), and doesn't add the user class to the usercollection class like it should.
I've tried everything I can think of to get to the bottom of this one, but no luck. Can anyone throw some light on why this might be happening?
jamcPosted Feb 13, 2009, 2:25 PM
Thanks for the reply, in the end I ditched the ArrayList setup in favour of ObjectModel.Collection(of T). That also resolved it.
AnthonyPosted Feb 6, 2009, 11:37 AM