Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to serialize an object as an INI file using VB.NET
Message
From
24/01/2014 11:10:38
 
 
General information
Forum:
ASP.NET
Category:
SOAP
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2000 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01592379
Message ID:
01592394
Views:
35
>>>>Hello Everybody,
>>>>
>>>>I am new to VB.NET and I want to serialize/deserialize and object to an INI file.
>>>>
>>>>I think I know how to so this to an XML file, but I need to do this to an INI file.
>>>>
>>>>Also the object that I wish to serialize/deserialize is a collection of classes.
>>>>
>>>>Can someone please help me with this.
>>>>
>>>>Thank you
>>>
>>>Can you give a simple example with a class definition and how you would want the file content to look ?
>>
>>Thank you very much for your reply!
>>
>>The class is as follows:
>>
>>
>>Imports System.Collections.Specialized
>>
>>Public Class User
>>    Public ID As String
>>    Public Name As String
>>    Public Password As String
>>    Public LoggedIn As Boolean
>>    Public AccessLevel As Integer
>>End Class
>>
>>Public Class Users
>>
>>    Inherits NameObjectCollectionBase
>>
>>    Sub Add(ByVal UserID As String, ByVal UserToAdd As User)
>>
>>        Me.BaseAdd(UserID, UserToAdd)
>>
>>    End Sub
>>
>>    Sub Clear()
>>
>>        Me.BaseClear()
>>
>>    End Sub
>>
>>    Sub Remove(ByVal UserID As String)
>>
>>        Me.Remove(UserID)
>>
>>    End Sub
>>
>>    Sub Remove(ByVal Index As Integer)
>>
>>        Me.Remove(Index)
>>
>>    End Sub
>>
>>    Default Property Item(ByVal UserID As String) As User
>>        Get
>>            Return DirectCast(Me.BaseGet(UserID), User)
>>        End Get
>>        Set(Value As User)
>>            Me.BaseSet(UserID, Value)
>>        End Set
>>    End Property
>>
>>    Default Property Item(ByVal Index As Integer) As User
>>        Get
>>            Return DirectCast(Me.BaseGet(Index), User)
>>        End Get
>>        Set(Value As User)
>>            Me.BaseSet(Index, Value)
>>        End Set
>>    End Property
>>
>>End Class
>>
>>
>>And the file content is as follows:
>>
>>[Gary]
>>OperatorID=Gary
>>OperatorName=Gary Niceguy
>>AccessLevel=4
>>OperatorPassword=50564348
>>
>>[Tester]
>>OperatorID=Tester
>>OperatorName=Tester Hester
>>AccessLevel=1
>>OperatorPassword=435242455243
>>
>>[Manager]
>>OperatorID=Manager
>>OperatorName=Manager
>>AccessLevel=4
>>OperatorPassword=5A565F50505443
>>
>>[New User]
>>OperatorID=New User
>>OperatorName=New User
>>AccessLevel=1
>>OperatorPassword=59524644445443
>>
>>[CurrentUsers]
>>0=Gary
>>1=Tester
>>2=Manager
>>3=New User
>>
>>4=New User 01
>>[New User 01]
>>OperatorID=New User 01
>>OperatorName=New User
>>AccessLevel=1
>>OperatorPassword=595246444454430500
>
>Do you just want to output this specific class and format or do you need a more generic solution?

Thank you for your reply.

I guess for now I would like to output this specific class to this specific format just so I can see how it would be done.
I hope that once I see how it is done for a specific case, I will have learned enough so that I can do it for a generic case.
Previous
Reply
Map
View

Click here to load this message in the networking platform