I'm trying to improve an old Class that I've wrote to manage an INI file, the Class contains 3 sub-Classes (File
, Key
, Section
) to separate and organize the procedures (procs for the ini in general, procs for manage the keys/values, and procs for manage the section names).
Well, the problem I have is that in the old class all the members were shared (props/vars/objects/methods) and obviouslly that could result in a disimbiguation, then I would like to try to perfectionate the visibility of the members, and there is where I'm stuck.
The current usage of the Class is like this:
INIFileManager.FilePath = "ini filepath"
dim iniexist as boolean = INIFileManager.File.Exist
And the usage that I would like should be like this:
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
Below is the relevant code for this example, I'm stuck on the Exist
method of the File
class 'cause I cannot access to the FilePath
variable which is at the top-level class since I don't set that variable and the Exist
method both as Shared
like I did on my old Class version...
...So how I can improve this?
NOTE: Please keep in mynd that the other 2 sub-Classes should have a method named Exist
and other methods with equal names such as "[Get]
", not only in the File
Class (I don't know if that could be a problem that could need more retouches).
''' <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