Solved

Serialization Question

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now