?
Solved

Serialization Question

Posted on 2006-06-13
4
Medium Priority
?
252 Views
Last Modified: 2012-05-05
How would i serialize an object into this form

item1=abc|item2=123|item3=abc|item4=123

where each item represents a property of the class and each value represents the property's value?
0
Comment
Question by:rodmjay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 8

Author Comment

by:rodmjay
ID: 16899932
If this is impossible, then a helper method that can take a serialized version of the above object and convert it to this format, thanks
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 16902747
You can do this via Reflection...here is a simple example:

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sc As New someClass
        sc.A = 911
        sc.B = "Emergency"
        sc.C = True
        TextBox1.Text = sc.ToString
    End Sub
End Class

Public Class someClass

    Private valA As Integer
    Private valB As String
    Private valC As Boolean

    Public Property A() As Integer
        Get
            Return valA
        End Get
        Set(ByVal value As Integer)
            valA = value
        End Set
    End Property

    Public Property B() As String
        Get
            Return valB
        End Get
        Set(ByVal value As String)
            valB = value
        End Set
    End Property

    Public Property C() As Boolean
        Get
            Return valC
        End Get
        Set(ByVal value As Boolean)
            valC = value
        End Set
    End Property

    Public Overrides Function ToString() As String
        Dim sb As New System.Text.StringBuilder
        Dim properties As System.ComponentModel.PropertyDescriptorCollection = System.ComponentModel.TypeDescriptor.GetProperties(Me)
        For Each p As System.ComponentModel.PropertyDescriptor In properties
            If sb.Length > 0 Then
                sb.Append("|")
            End If
            sb.Append(p.Name & "=" & p.GetValue(Me))
        Next
        Return sb.ToString
    End Function

End Class
0
 
LVL 8

Author Comment

by:rodmjay
ID: 16904744
I guess that works.  Not exactly serialization, but as close as I need it.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16904814
Serialization puts the object into it's own format...typically XML or Binary serialization...which is not what you specified.

Do you need to see code to write that string to a file?
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question