Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Object Property Serialization

Object Property Serialization

Scheduled Pinned Locked Moved Visual Basic
xmljson
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tom John
    wrote on last edited by
    #1

    Hey Guys I'm having problems serializing an class that has an object property, even though the object in the instance of that class is serializable. I've cut the code down to demonstrate:

    Option Strict On

    Public Class Test

    Public Sub New()
    End Sub
    
    Dim m\_text As String
    Public Property Text() As String
        Get
            Return m\_text
        End Get
        Set(ByVal Value As String)
            m\_text = Value
        End Set
    End Property
    

    End Class

    Public Class TestTag

    Public Sub New()
    End Sub
    
    Dim m\_text As String
    Public Property Text() As String
        Get
            Return m\_text
        End Get
        Set(ByVal Value As String)
            m\_text = Value
        End Set
    End Property
    
    Dim m\_tag As Object
    Public Property Tag() As Object
        Get
            Return m\_tag
        End Get
        Set(ByVal Value As Object)
            m\_tag = Value
        End Set
    End Property
    

    End Class

    Public Class StartUp

    Public Shared Sub Main()
    
        Dim ser As New Xml.Serialization.XmlSerializer(GetType(TestTag))
        Dim file As New System.IO.StreamWriter("c:\\temp\\test.xml")
        Dim obj1 As New TestTag
        Dim obj2 As New Test
    
        obj1.Text = "TestTag Object"
        obj2.Text = "Test Object"
        obj1.Tag = obj2
    
        ser.Serialize(file, obj1)
    
        file.Close()
    
        MsgBox("Object Serialized")
    
    End Sub
    

    End Class

    Really, all i think all i need to do is change the Tag property of the TagTest class to an type that is know to be serialized, i have tried ISerializable but it don't want to know. Failing that, i assume i'll just have to implement ISerializable on the TagTest class, but it seems a lot of work just for the one property. Any ideas greatly appreciated. Tom

    D 1 Reply Last reply
    0
    • T Tom John

      Hey Guys I'm having problems serializing an class that has an object property, even though the object in the instance of that class is serializable. I've cut the code down to demonstrate:

      Option Strict On

      Public Class Test

      Public Sub New()
      End Sub
      
      Dim m\_text As String
      Public Property Text() As String
          Get
              Return m\_text
          End Get
          Set(ByVal Value As String)
              m\_text = Value
          End Set
      End Property
      

      End Class

      Public Class TestTag

      Public Sub New()
      End Sub
      
      Dim m\_text As String
      Public Property Text() As String
          Get
              Return m\_text
          End Get
          Set(ByVal Value As String)
              m\_text = Value
          End Set
      End Property
      
      Dim m\_tag As Object
      Public Property Tag() As Object
          Get
              Return m\_tag
          End Get
          Set(ByVal Value As Object)
              m\_tag = Value
          End Set
      End Property
      

      End Class

      Public Class StartUp

      Public Shared Sub Main()
      
          Dim ser As New Xml.Serialization.XmlSerializer(GetType(TestTag))
          Dim file As New System.IO.StreamWriter("c:\\temp\\test.xml")
          Dim obj1 As New TestTag
          Dim obj2 As New Test
      
          obj1.Text = "TestTag Object"
          obj2.Text = "Test Object"
          obj1.Tag = obj2
      
          ser.Serialize(file, obj1)
      
          file.Close()
      
          MsgBox("Object Serialized")
      
      End Sub
      

      End Class

      Really, all i think all i need to do is change the Tag property of the TagTest class to an type that is know to be serialized, i have tried ISerializable but it don't want to know. Failing that, i assume i'll just have to implement ISerializable on the TagTest class, but it seems a lot of work just for the one property. Any ideas greatly appreciated. Tom

      D Offline
      D Offline
      Dr_X
      wrote on last edited by
      #2

      Try try tagging the classes . _ Public Class Test .... _ Public Class TestTag .... If that doesn't work you may have to declare the Tag property Test. Michael I firmly believe that any man's finest hour, the greatest fulfillment of all that he holds dear, is that moment when he has worked his heart out in a good cause and lies exhausted on the field of battle - victorious. Vince Lombardi (1913-1970)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups