XML Serialization of custom collection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jamie_m_

    XML Serialization of custom collection

    I have a custom collection ... clFile that INHERITS from NameObjectColle ctionBase the problem is, when I try to create an xmlserializer instance i get an error

    You must implement a default accessor on brWAP.clFile because it inherits from ICollectio

    I must be having a thick day because I dont have a clue what the error message means. (I have written a defaut property called ITEM in the clFile class


  • More info...

    #2
    RE: XML Serialization of custom collection

    'Here is the code...
    'Classes to abstract a FILE entity that is persisted in the databas
    Imports System.Xml.Seri alizatio
    Imports dalWAP.dalWA

    'A worker class to get the data from the Database and save it bac
    Public Class egFil

    Sub New(
    End Su

    'Get a collection of FILE entities from the databas
    Public Function GetCollection(O ptional ByVal FileID As Integer = -1) As clFil
    Dim dsFiles As DataSe
    Dim serializer As XmlSerialize

    Dim oXML As Xml.XmlDataDocu men
    Dim oclFile As clFil

    Dim oXMLr As Xml.XmlNodeRead e

    '-------
    'this is the line that gives the erro
    'You must implement a default accessor on brWAP.clFile because it inherits from ICollection
    '-------
    serializer = New XmlSerializer(G etType(clFile)

    'Call the data access layer to pysically read from the DB to a datase
    dsFiles = GetFiles(FileID

    'load the dataset into an xml documen
    oXML = New Xml.XmlDataDocu ment(dsFiles

    oXMLr = New Xml.XmlNodeRead er(oXML
    'deserialise the xml into a collection of FILE entitie
    oclFile = CType(serialize r.Deserialize(o XMLr), clFile

    End Functio

    End Clas

    'Strongly Typed collection of FILE entitie
    <XmlType(TypeNa me:="clFile")>
    Public Class clFil
    Inherits System.Collecti ons.Specialized .NameObjectColl ectionBas

    Public Sub New(
    'default constructo
    End Su

    Public Function Add(ByVal value As cdFile) As Boolea
    Me.BaseAdd("_" & value.FileID, value

    End Functio

    <XmlElementAttr ibute("cdFile", GetType(cdFile) )>
    Default Public Overloads ReadOnly Property Item(ByVal Key As String) As cdFil
    Ge
    Return Me.BaseGet("_" & Key
    End Ge
    End Propert

    Public Function ItemAt(ByVal value As Integer) As cdFil
    Return Me.BaseGet(valu e
    End Functio

    Public Function Remove(ByVal value As Integer) As cdFil
    Dim ocdFile As cdFil
    ocdFile = Me.Item(value
    Me.BaseRemove(" _" & value
    Remove = ocdFil
    ocdFile = Nothin
    End Functio

    Public Function RemoveAt(ByVal value As Integer) As cdFil
    Dim ocdFile As cdFil
    ocdFile = Me.ItemAt(value
    Me.BaseRemoveAt (value
    RemoveAt = ocdFil
    ocdFile = Nothin
    End Functio

    End Clas

    '<summary
    '<para>Represen ts a FILE entity</para
    '<para>A FILE entity implemnts a reference to an external file</para
    '</summary><XmlTyp e(TypeName:="cd File")>
    Public Class cdFil
    Private mintFileID As Intege
    Private mstrTheName As Strin
    Private mstrThePath As Strin

    Private mblnNew As Boolea
    Private mblnDirty As Boolea
    Private mblnDeleted As Boolea

    Overrides Function GetHashCode() As Intege
    Return mintFileID.GetH ashCod
    End Functio

    '<summary
    '<para>If record ID's are equal, objects are equal</para
    '</summary
    Overloads Function Equals(ByVal ID As Integer) As Boolea
    If mblnNew The
    Return Fals
    Els
    Return (ID = mintFileID
    End I
    End Functio

    Overloads Function Equals(ByVal Test_cdFile As cdFile) As Boolea
    If mblnNew The
    Return Fals
    Els
    If Test_cdFile Is Nothing The
    Return Fals
    Els
    Return (mintFileID = Test_cdFile.Fil eID
    End I
    End I

    End Functio

    '<summary
    '<para>new instance of existing record</para
    '</summary
    Sub New(ByVal FileID As Long, ByVal TheName As String, ByVal ThePath As String
    mintFileID = FileI
    mstrTheName = TheNam
    mstrThePath = ThePat
    mblnDirty = Fals
    mblnNew = Tru
    End Su

    '<summary
    '<para>for a really new file</para
    '</summary
    Sub New(ByVal TheName As String, ByVal ThePath As String
    mstrTheName = TheNam
    mstrThePath = ThePat
    mblnNew = Tru
    mblnDirty = Tru

    End Su

    '<summary
    '<para>empty constructor for xml de-serialisation</para
    '</summary>
    Sub New()

    mblnNew = False
    mblnDirty = False
    End Sub

    Public Overloads Function Saved() As Boolean
    mblnDirty = False
    Return True
    End Function

    Public Overloads Function Saved(ByVal FileID As Long) As Boolean
    mblnDirty = False
    mblnNew = False
    mintFileID = FileID
    Return True
    End Function

    Public Function Delete() As Boolean
    mblnDeleted = True
    Return mblnDeleted
    End Function
    <XmlIgnore()> _
    Public ReadOnly Property Dirty() As Boolean
    Get
    Return mblnDirty
    End Get
    End Property
    <XmlIgnore()> _
    Public ReadOnly Property Deleted() As Boolean
    Get
    Deleted = mblnDeleted
    End Get
    End Property
    Public Property FileID() As Integer
    Get
    Return mintFileID
    End Get
    Set(ByVal Value As Integer)
    mintFileID = Value
    End Set
    End Property

    Public Property TheName() As String
    Get
    Return mstrTheName
    End Get
    Set(ByVal Value As String)
    mstrTheName = Value
    End Set
    End Property

    Public Property ThePath() As String
    Get
    Return mstrThePath
    End Get
    Set(ByVal Value As String)
    mstrThePath = Value
    End Set
    End Property
    End Class

    Comment

    Working...