Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Serialization Question

Posted on 2006-06-13
4
Medium Priority
?
253 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Screencast - Getting to Know the Pipeline
Suggested Courses

610 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