学习vb.net,练习写了一个ini文件类,试用List。
Imports System.IO
Imports System.Text
#Region "配置文件 CIni类定义"
Public Class CIni
Inherits CSections
Public Property FullName As String
Public Sub New(ByVal _IniFullName As String)
FullName = _IniFullName
If Dir(_IniFullName) <> "" Then
ReadFromIni()
End If
End Sub
#Region "属性:Path,返回INI文件的路径。"
Public ReadOnly Property Path As String
Get
Dim iIndex As Integer = FullName.Split("\").Last().Length
Return FullName.Substring(0, FullName.Length - iIndex)
End Get
End Property
#End Region
#Region "属性:Name,返回INI短文件名。"
Public ReadOnly Property Name As String
Get
Return FullName.Split("\").Last
End Get
End Property
#End Region
#Region "属性:Sections,返回节列表。"
Public Property Sections As CSections
Get
Return Me
End Get
Set(ByVal _Sections As CSections)
For Each s As CSection In _Sections
Add(s)
Next
End Set
End Property
#End Region
#Region "方法:ReadFromIni,把磁盘INI设置文件读取到内存中。"
''' <summary>
''' 把List结构的INI文件转换成INI类结构
''' </summary>
''' <remarks></remarks>
Private Function ReadFromIni() As Boolean
' Dim bRead = True
Dim listIni As List(Of String) = ReadIniToList()
If IsNothing(listIni) Then
Return False
End If
Dim strSectionName As String = ""
Dim strNote As String = ""
With listIni
For i As Integer = 0 To .Count - 1
If .Item(i).First = ";" Then
strNote = .Item(i).Substring(1, .Item(i).Length - 1)
ElseIf .Item(i).First = "[" Then
strSectionName = .Item(i).Substring(1, .Item(i).Length - 2)
Add(New CSect