Results 1 to 4 of 4

Thread: Property doesnt get serialized

  1. #1

    Thread Starter
    Addicted Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    196

    Property doesnt get serialized

    I have the following class that implements IList interface.

    When serializing the collection gets written, but the properties Type, Start & End do not.
    Can anyone explain why is that?

    Code:
    <Serializable>
    Public Class License
        Implements IList(Of LicensePart)
    
    #Region "Private Member(s)"
        Private InnerList As New List(Of LicensePart)
    #End Region
    #Region "Properties"
        Public Property Type As LicenseType = LicenseType.Trail
        Public Property Start As DateTime
        Public Property [End] As DateTime
    #End Region
    #Region "Constructor(s)"
    
    #End Region
    #Region "IList"
        Default Public Property Item(index As Integer) As LicensePart Implements IList(Of LicensePart).Item
            Get
                Return InnerList.Item(index)
            End Get
            Set(value As LicensePart)
                InnerList.Item(index) = value
            End Set
        End Property
    
        Public ReadOnly Property Count As Integer Implements ICollection(Of LicensePart).Count
            Get
                Return InnerList.Count
            End Get
        End Property
    
        <System.Xml.Serialization.XmlIgnore>
        Public ReadOnly Property IsReadOnly As Boolean Implements ICollection(Of LicensePart).IsReadOnly
            Get
                Return False
            End Get
        End Property
    
        Public Sub Insert(index As Integer, item As LicensePart) Implements IList(Of LicensePart).Insert
            InnerList.Insert(index, item)
        End Sub
    
        Public Sub RemoveAt(index As Integer) Implements IList(Of LicensePart).RemoveAt
            InnerList.RemoveAt(index)
        End Sub
    
        Public Sub Add(item As LicensePart) Implements ICollection(Of LicensePart).Add
            InnerList.Add(item)
        End Sub
    
        Public Sub Clear() Implements ICollection(Of LicensePart).Clear
            InnerList.Clear()
        End Sub
    
        Public Sub CopyTo(array() As LicensePart, arrayIndex As Integer) Implements ICollection(Of LicensePart).CopyTo
            InnerList.CopyTo(array, arrayIndex)
        End Sub
    
        Public Function IndexOf(item As LicensePart) As Integer Implements IList(Of LicensePart).IndexOf
            Return InnerList.IndexOf(item)
        End Function
    
        Public Function Contains(item As LicensePart) As Boolean Implements ICollection(Of LicensePart).Contains
            Return InnerList.Contains(item)
        End Function
    
        Public Function Remove(item As LicensePart) As Boolean Implements ICollection(Of LicensePart).Remove
            Return InnerList.Remove(item)
        End Function
    
        Public Function GetEnumerator() As IEnumerator(Of LicensePart) Implements IEnumerable(Of LicensePart).GetEnumerator
            Return InnerList.GetEnumerator
        End Function
    
        Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
            Return InnerList.GetEnumerator
        End Function
    #End Region
    End Class
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,829

    Re: Property doesnt get serialized

    W/o seeing how you did the serialization, hard to say exactly why, but presumably it's because you serialized the collection, or specifically the IList ... not the License

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    196

    Re: Property doesnt get serialized

    Sorry for the missing code

    the place where the serializiation takes place

    Code:
    Public Class Form1
        Private MyLicense As New License
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            Me.MyLicense.Type = LicenseType.Server
            Me.MyLicense.Add(New LicensePart With {.Application = LicenseProgram.Dynfos_Pro, .Quantity = 10, .InstanceBased = False})
            Me.MyLicense.Add(New LicensePart With {.Application = LicenseProgram.SceneAnalyzer, .Quantity = 2, .InstanceBased = False})
    
    
            Using Fsd As New SaveFileDialog
                If Fsd.ShowDialog = DialogResult.OK Then
                    Serializer.Save(Of License)(Me.MyLicense, Fsd.FileName)
                End If
            End Using
        End Sub
    End Class
    and the Serializer

    Code:
    Imports System.IO
    Imports System.Text
    Imports System.Xml
    Imports System.Xml.Serialization
    
    
    Public Class Serializer
    
        Public Shared Sub Save(Of T)(ByVal value As T, ByVal fileName As String)
            Using fs As FileStream = File.Open(fileName, FileMode.Create)
                Save(Of T)(value, fs)
            End Using
        End Sub
    
        Public Shared Sub Save(Of T)(ByVal value As T, ByVal stream As Stream)
            GetSerializer(Of T)().Serialize(stream, value)
        End Sub
    
        Public Shared Function Save(Of T)(ByVal value As T) As Byte()
            Using ms As MemoryStream = New MemoryStream()
                Save(Of T)(value, ms)
                Return ms.GetBuffer()
            End Using
        End Function
    
        Public Shared Function Save(Of T)(ByVal value As T, ByVal encoding As Encoding) As String
            Return encoding.GetString(Save(Of T)(value))
        End Function
    
        Public Shared Function Load(Of T)(ByVal stream As Stream) As T
            Return CType(GetSerializer(Of T)().Deserialize(stream), T)
        End Function
    
        Public Shared Function Load(Of T)(ByVal file As FileInfo) As T
            Using fs As FileStream = file.Open(FileMode.Open)
                Return Load(Of T)(fs)
            End Using
        End Function
    
        Public Shared Function Load(Of T)(ByVal data As Byte()) As T
            Using ms As MemoryStream = New MemoryStream(data)
                Return Load(Of T)(ms)
            End Using
        End Function
    
        Public Shared Function Load(Of T)(ByVal data As String) As T
            Return Load(Of T)(Encoding.ASCII.GetBytes(data))
        End Function
    
        Public Shared Function Load(Of T)(ByVal doc As XmlDocument) As T
            Return Load(Of T)(doc.ToString())
        End Function
    
        Private Shared Function GetSerializer(Of T)() As XmlSerializer
            Return New XmlSerializer(GetType(T))
        End Function
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  4. #4

    Thread Starter
    Addicted Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    196

    Re: Property doesnt get serialized

    As you can see (atleast as i programmed my thoughts rite) it is the License thats getting serialized...or atleast it should be
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width