Serialize a class that implements IEnumerable

倖福魔咒の 提交于 2020-01-17 05:31:25

问题


I want to serialize this class I have no idea how to do it:

Public Class colCustomRecurringClaims
    Implements IEnumerable


    #Region "Declarations"

    Private mobjColl As New Collection
    Private mobjSys As LifeCO.clsSys

    #End Region 'Declarations

    #Region "Framework Functions"
    Public Sub New(pobjSys As LifeCO.clsSys)
        mobjSys = pobjSys
    End Sub

    Public Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
        Return mobjColl.GetEnumerator
    End Function

    Private Function GetUC() As MIH_CustomUC.colRecurringClaimsUC
        If Not Sys.Configured Then
            Sys.Configure()
        End If
        Return New MIH_CustomUC.colRecurringClaimsUC
    End Function

    Public ReadOnly Property Sys() As LifeCO.clsSys
        Get
            Return mobjSys
        End Get
    End Property

    Public ReadOnly Property Count() As Long
        Get
            Return mobjColl.Count
        End Get
    End Property

    #End Region 'Framework Functions End: NB Do not delete

    #Region "Properties "

    #End Region 'Properties End: NB Do not delete

    #Region "Standard Functions"

    Public Sub Add(ByVal pobj As MIH_CustomCO.clsCustomRecurringClaims)
        Try
            If pobj.GID = "" Then
                mobjColl.Add(pobj)
            Else
                mobjColl.Add(pobj, pobj.GID)
            End If
        Catch er As Exception
            LogEvent(er)
            Throw er
        End Try
    End Sub

    Public Function ItemByKey(ByVal pstrGID As String) As MIH_CustomCO.clsCustomRecurringClaims
        Try
            Return CType(mobjColl.Item(pstrGID), MIH_CustomCO.clsCustomRecurringClaims)
        Catch er As Exception
            LogEvent(er)
            Throw er
        End Try
    End Function

    Public Function ContainsItem(ByVal pstrGID As String) As Boolean
        Try
            For Each lobj As MIH_CustomCO.clsCustomRecurringClaims In mobjColl
                If lobj.GID = pstrGID Then Return True
            Next
            Return False
        Catch er As Exception
            LogEvent(er)
            Throw er
        End Try
    End Function

    Public Function Item(ByVal index As Integer) As MIH_CustomCO.clsCustomRecurringClaims
        Try
            Return CType(mobjColl.Item(index), MIH_CustomCO.clsCustomRecurringClaims)
        Catch er As Exception
            LogEvent(er)
            Throw er
        End Try
    End Function


    Public Function LoadAllByClaimGID(ByVal pstrClaimGID As String) As Boolean
        Dim lstrXML As String = ""
        Try
            mobjColl = New Collection
            LoadAllByClaimGID = GetUC.f_LoadAllByClaimGID(Sys.Pack, pstrClaimGID, lstrXML)
            UnPack(lstrXML)
        Catch er As Exception
            LogEvent(er)
            Throw er
        End Try
    End Function


    Public Function Pack() As String
        Dim lobjCustomFinancialTransaction As MIH_CustomCO.clsCustomRecurringClaims
        Dim lstrXML As String = ""
        Try
            lstrXML = " <CustomRecurringClaim> "
            For Each lobjCustomFinancialTransaction In mobjColl
                lstrXML = lstrXML & lobjCustomFinancialTransaction.Pack
            Next
            Return lstrXML & " </CustomRecurringClaim>"
        Catch er As Exception
            LogEvent(er)
            Throw er
        End Try
    End Function

    Public Sub UnPack(ByVal pstrXML As String)
        Dim lobjDOM As System.Xml.XmlDocument
        Dim lobjNode As System.Xml.XmlNode
        Dim lobjNodeList As System.Xml.XmlNodeList
        Dim lobjlobjCustomRecurringClaims As MIH_CustomCO.clsCustomRecurringClaims

        Try
            lobjDOM = New Xml.XmlDocument()
            Try
                lobjDOM.LoadXml(pstrXML)
            Catch
                Exit Sub
            End Try

            'locate base entries in XML
            lobjNodeList = lobjDOM.SelectNodes("CustomRecurringClaim/CustomRecurringClaim")
            If lobjNodeList Is Nothing Then Exit Sub

            For Each lobjNode In lobjNodeList
                lobjlobjCustomRecurringClaims = New MIH_CustomCO.clsCustomRecurringClaims(Sys)
                lobjlobjCustomRecurringClaims.UnPack(lobjNode.OuterXml)
                Add(lobjlobjCustomRecurringClaims)
            Next
            lobjNodeList = Nothing
            lobjNode = Nothing
            lobjDOM = Nothing

        Catch Er As Exception
            LogEvent(Er)
            Throw Er
        End Try

    End Sub

    #End Region 'Standard Functions End: NB Do not delete

    #Region "Custom Functions"

    #End Region 'Custom Functions End: NB Do not delete


    End Class

I get an error:

System.Runtime.Serialization.SerializationException: Type 'System.Xml.XmlElement' in Assembly 'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

来源:https://stackoverflow.com/questions/37295768/serialize-a-class-that-implements-ienumerable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!