Imports System.Reflection Imports System.IO Public Class cINI Public sAppPath As String = Application.StartupPath Dim cINIPropertys = New List(Of MemberInfo) Dim INIfile As String = sAppPath & "\config.ini" Property prop_TSSitzungenAnzeigen As Boolean = True Property prop_Kompansicht As Boolean = True Property prop_FreiHostsAnzeigen As Boolean = False Property prop_DHCPClientsAnzeigen As Boolean = False Property prop_ToolsPanelAnzeizgen As Boolean = False Property prop_Pano As Boolean = False Public Function LoadParameters() If Not File.Exists(Application.StartupPath & "\config.ini") Then File.Create(Application.StartupPath & "\config.ini") Exit Function End If Dim test As String = "" Dim cINIPropertysNames = New List(Of String) Dim t As Type = GetType(cINI) For Each member As MemberInfo In t.GetMembers If member.Name.ToString Like "prop_*" Then cINIPropertys.Add(member) cINIPropertysNames.Add(member.Name) 'MsgBox(member.Name) End If Next Try Dim lines = IO.File.ReadAllLines(sAppPath & "\config.ini") If lines.Count <= 1 Then Me.save() Try Dim colCount = lines.First.Split(";"c).Length Catch ' Me.save(True) End Try ' Dim cINIPropertys = New List(Of MemberInfo) For Each meh In cINIPropertys test &= meh.Name.ToString & vbCrLf Next ' MsgBox(test) For Each member As MemberInfo In cINIPropertys For Each line In lines Dim objFields = From field In line.Split(";"c) Select Case objFields(0).ToString Case member.Name ' MsgBox(objFields(0).ToString) 'MsgBox(objFields(1).ToString) SetPropertyValueByName(Me, member.Name, objFields(1)) ' _ConType = objFields(1).ToString ' Return True ' Exit Function End Select Next Next ' MsgBox(prop_TSSitzungenAnzeigen) Return False Catch ex As Exception MsgBox("Fehler beim Lesen config.ini: " & vbCrLf & ex.Message) End Try End Function Public Shared Function SetPropertyValueByName(obj As [Object], name As String, value As [Object]) As Boolean Dim prop = obj.[GetType]().GetProperty(name, BindingFlags.[Public] Or BindingFlags.Instance) If prop Is Nothing OrElse Not prop.CanWrite Then Return False End If Try prop.SetValue(obj, value, Nothing) Catch Dim b As Boolean = False If value = "True" Or value = "1" Then b = True Else b = False End If prop.SetValue(obj, b, Nothing) End Try Return True End Function Public Shared Function GETPropertyValueByName(obj As [Object], name As String) Dim prop = obj.[GetType]().GetProperty(name, BindingFlags.[Public] Or BindingFlags.Instance) Return prop.GetValue(obj) End Function Function save(Optional ByVal echostring As Boolean = False) Dim savestring As String = "" For Each member As MemberInfo In cINIPropertys savestring &= member.Name & ";" & GETPropertyValueByName(Me, member.Name) & ";" & vbCrLf Next If echostring = True Then MsgBox(savestring) Exit Function End If Dim objWriter As New System.IO.StreamWriter(INIfile) objWriter.Write(savestring) objWriter.Close() End Function End Class