By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,023 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

customer configuration

P: n/a
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("Clock WatcherCollection",
IsRequired:=True)_
Friend ReadOnly Property ClockWatcherCollection() As
ClockWatchCollection
Get
Return Me("ClockWatcherCollection")
End Get
End Property

End Class

Friend Class ClockWatchCollection

Inherits System.Configuration.ConfigurationElementCollectio n

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>
May 18 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Dick,

From your description, you're wantting to add some custom configuration
section to the applicaiton config file, and some of the configure element
contains item collections, and you met some problem to get complex type
collection in the custom configsection, correct?

Based on my understanding, the .net framework 2.0 custom configuration
interface support two kinds of custom configuration handler:

1. derive your custom configuration section class from
"ConfigurationSection" class, and any sub property/section from
"ConfigurationElement" or "ConfigurationElementCollection". And if you
want to add custom item collection this way, you can only contains a single
type of element in one colleciton and use "<add>", "<remove>" element to
add or remove item. e.g.

==================
<urls>
<clear />
<add
name="Microsoft" url="http://www.microsoft.com" port="0"
lockAllAttributesExcept="port" />
<add
name="Contoso" url="http://www.contoso.com/" port="8080"
lockAllAttributesExcept="port" lockItem="true" />
</urls>
========================

and it only support simple/basic types rather than nested complex
properties.
2. For your scenario, if you want to add complex nested properties for each
item in configuration colleciton/list, I'm afraid you may need to write a
custom section handler and use raw XML API or XML serialization api to
manage the XML content of the section directly. see the following MSDN
reference:

#How to: Create Custom Configuration Sections Using
IConfigurationSectionHandler
http://msdn2.microsoft.com/en-us/library/ms228056.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.



May 21 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.