Solved

Serialization Question

Posted on 2006-06-13
4
248 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
  • 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 250 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.net Progress Bar - Maximum Value too large 2 26
MYSQL responding very slow 3 50
Data organization issue 7 37
Find date of 2nd Thursday of each month 3 34
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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.

733 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