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 10:34:30
 
 
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:
01592391
Views:
45
>>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform