INI ファイルを管理するために作成した古いクラスを改善しようとしています。クラスには、手順を分離して整理するための 3 つのサブクラス ( File
、Key
、Section
) が含まれています (一般的には ini のプロシージャ、キーを管理するプロシージャ/値、およびセクション名を管理するためのプロシージャ)。
さて、私が抱えている問題は、古いクラスではすべてのメンバーが共有されており (props/vars/objects/methods)、明らかにそれが非類似性につながる可能性があることです。メンバーの可視性を完全なものにしたいと思います。私が立ち往生しているところがあります。
クラスの現在の使用法は次のようになります。
INIFileManager.FilePath = "ini filepath"
dim iniexist as boolean = INIFileManager.File.Exist
そして、私が望む使用法は次のようになります:
dim ini as new inifilemanager("ini filepath", textencoding)
dim iniexist as boolean = ini.file.exist
dim another_ini as new inifilemanager("another ini filepath without any kind of conflict with the first instance", textencoding)
dim another_iniexist as boolean = another_ini.file.exist
以下は、この例に関連するコードです。変数とメソッドの両方を私のように設定していないため、最上位クラスにある変数にアクセスできないためExist
、クラスのメソッドに行き詰まっています私の古いクラスバージョンでやった...File
FilePath
Exist
Shared
...では、どうすればこれを改善できますか?
注:他の 2 つのサブクラスには、クラス内だけでなく、名前が付けられたメソッドExist
と、" " などの同じ名前の他のメソッドが必要であることに注意してください (それが問題になるかどうかはわかりませんが、さらに多くのことが必要になる可能性がありますレタッチします)。[Get]
File
''' <summary>
''' Manages an INI file and it's sections to load/save values.
''' </summary>
Public Class INIFileManager
#Region " Properties "
''' <summary>
''' Indicates the initialization file location.
''' </summary>
Private Property FilePath As String = String.Empty
''' <summary>
''' Indicates the initialization file encoding to read/write.
''' </summary>
Private Property TextEncoding As System.Text.Encoding = System.Text.Encoding.Default
#End Region
#Region " Constructors "
''' <summary>
''' Initializes a new instance of the <see cref="INIFileManager" /> class.
''' </summary>
''' <param name="IniFile">
''' Indicates the initialization file location.
''' </param>
''' <param name="TextEncoding">Indicates a textencoding to read/write the iniinitialization file.</param>
Public Sub New(Optional ByVal IniFile As String = Nothing,
Optional ByVal TextEncoding As System.Text.Encoding = Nothing)
If Not String.IsNullOrEmpty(IniFile) Then
Me.FilePath = IniFile
Else
Me.FilePath = IO.Path.Combine(Application.StartupPath,
Process.GetCurrentProcess().ProcessName & ".ini")
End If
If Not TextEncoding Is Nothing Then
Me.TextEncoding = TextEncoding
End If
End Sub
#End Region
''' <summary>
''' Contains a set of procedures to manage the INI file in a general way.
''' </summary>
Private Class [File]
''' <summary>
''' Checks whether the initialization file exist.
''' </summary>
''' <returns>True if initialization file exist, otherwise False.</returns>
Public Function Exist() As Boolean
Return IO.File.Exists(MyBase.FilePath)
End Function
' More irrelevant methods here that need to access to props and vars of the top-level class...
End Class
' another class here...
' and another class here...
End Class