G
Guest
My Windows Application stores its configuration values in app.config and
these are typed and accessed via corresponding classes, something like this...
<configSections>
<section name="Watcher"/>
</configSections>
<Watcher>
<ClockWatcherCollection>
<add Name="Blah"/>
</ClockWatcherCollection>
</Watcher>
Friend Class Watcher
Inherits System.Configuration.ConfigurationSection
<System.Configuration.ConfigurationProperty("ClockWatcherCollection",
IsRequired:=True)> _
Friend ReadOnly Property ClockWatcherCollection() As
ClockWatchCollection
Get
Return Me("ClockWatcherCollection")
End Get
End Property
End Class
Friend Class ClockWatchCollection
Inherits System.Configuration.ConfigurationElementCollection
Protected Overloads Overrides Function CreateNewElement() As
System.Configuration.ConfigurationElement
Return New ClockWatch
End Function
Protected Overrides Function GetElementKey(ByVal Element As
System.Configuration.ConfigurationElement) As Object
Return CType(Element, ClockWatch).Name
End Function
Friend Shadows Function Item(ByVal Name As String) As ClockWatch
Return MyBase.BaseGet(Name)
End Function
End Class
Friend Class ClockWatch
Inherits System.Configuration.ConfigurationSection
<System.Configuration.ConfigurationProperty("Name", IsRequired:=True)> _
Friend ReadOnly Property Name() As String
Get
Return Me("Name")
End Get
End Property
End Class
This works fine for simple types, such as the Name property above, but I
can’t see how to do the same for complex types like the collection of
Notification types and the LogFile type below…
<Watcher>
<ClockWatcherCollection>
<add Name="Blah">
<Notification Address="Blah"/>
<Notification Address="Blah"/>
<Notification Address="Blah"/>
<LogFile Name="Blah", MaxSize="Blah", Delete="Blah"/>
</add>
</ClockWatcherCollection>
</Watcher>
these are typed and accessed via corresponding classes, something like this...
<configSections>
<section name="Watcher"/>
</configSections>
<Watcher>
<ClockWatcherCollection>
<add Name="Blah"/>
</ClockWatcherCollection>
</Watcher>
Friend Class Watcher
Inherits System.Configuration.ConfigurationSection
<System.Configuration.ConfigurationProperty("ClockWatcherCollection",
IsRequired:=True)> _
Friend ReadOnly Property ClockWatcherCollection() As
ClockWatchCollection
Get
Return Me("ClockWatcherCollection")
End Get
End Property
End Class
Friend Class ClockWatchCollection
Inherits System.Configuration.ConfigurationElementCollection
Protected Overloads Overrides Function CreateNewElement() As
System.Configuration.ConfigurationElement
Return New ClockWatch
End Function
Protected Overrides Function GetElementKey(ByVal Element As
System.Configuration.ConfigurationElement) As Object
Return CType(Element, ClockWatch).Name
End Function
Friend Shadows Function Item(ByVal Name As String) As ClockWatch
Return MyBase.BaseGet(Name)
End Function
End Class
Friend Class ClockWatch
Inherits System.Configuration.ConfigurationSection
<System.Configuration.ConfigurationProperty("Name", IsRequired:=True)> _
Friend ReadOnly Property Name() As String
Get
Return Me("Name")
End Get
End Property
End Class
This works fine for simple types, such as the Name property above, but I
can’t see how to do the same for complex types like the collection of
Notification types and the LogFile type below…
<Watcher>
<ClockWatcherCollection>
<add Name="Blah">
<Notification Address="Blah"/>
<Notification Address="Blah"/>
<Notification Address="Blah"/>
<LogFile Name="Blah", MaxSize="Blah", Delete="Blah"/>
</add>
</ClockWatcherCollection>
</Watcher>