正在阅读:一种简便实效的配置文件读写方法一种简便实效的配置文件读写方法

2004-11-01 15:25 出处:CSDN 作者:lzmtw 责任编辑:linjixiong


   Public Sub Add(ByVal ConnectionInfo As Item)

        If ConnectionInfo Is Nothing Then Exit Sub

        If m_Count > 0 Then

            If Not Me.ConnectionInfo(ConnectionInfo.ID) Is Nothing Then

                MsgBox(ID.ToString & "已存在")

                Exit Sub

            End If

        End If

        ReDim Preserve Me.Items(m_Count)

        Me.Items(m_Count) = ConnectionInfo

        m_Count += 1

    End Sub

    '取指定ID的配置信息

    Public ReadOnly Property ConnectionInfo(ByVal ID As Integer) As Item

        Get

            Dim mItem As Item

            Dim i As Integer

            For i = 0 To m_Count - 1

                If Me.Items(i).ID = ID Then

                    mItem = Me.Items(ID)

                    Exit For

                End If

            Next

            Return mItem

        End Get

    End Property

    '序列化并保存到指定文件

    Public Sub SaveXmlFile(ByVal FileName As String)

        If Me Is Nothing Then Exit Sub

        Dim XmlWriter As New System.IO.StreamWriter(FileName, False)

        XmlWriter.Write(SerializeClass.GetXML(Me))

        XmlWriter.Close()

    End Sub

    '从指定文件读取反序列化转为对象

    Public Function LoadXmlFile(ByVal FileName As String) As Config

        Dim XmlReader As New System.IO.StreamReader(FileName, System.Text.Encoding.Default)

 


察看评论详细内容 我要发表评论
作者笔名 简短内容 发表时间
:

键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品