Solved

Serialization Question

Posted on 2006-06-13
4
245 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 85

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 85

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 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