Generics in custom configuration sections
Posted
by Jonn
on Stack Overflow
See other posts from Stack Overflow
or by Jonn
Published on 2010-05-05T00:07:16Z
Indexed on
2010/05/05
0:48 UTC
Read the original article
Hit count: 256
.NET
|configuration-files
I tried making a custom configuration class that went on like this:
WatcherServiceInfoSection<TWatcherServiceDetailElement>
where TWatcherServiceDetailElement is a ConfigurationElement
inside it.
Now when I call the type in the ConfigSections
area of AppConfig I get the error:
An error occurred creating the configuration section handler for WatcherServiceInfo:
Could not load type 'Library.Common.Utilities.ConfigurationHandler.WatcherServiceInfoSection<ASNDPService.Configuration.WatcherServiceDetailElement>' from assembly
Is what I'm doing possible? Can I have generic types in the type attribute for a custom section element?
EDIT
Additionally, how about ConfigurationElementCollection
objects? Like in the above example, how could I do a
[ConfigurationProperty("WatcherServiceDetails", IsRequired = true,
IsDefaultCollection = true)]
[ConfigurationCollection(typeof(TWatcherServiceDetailElement), AddItemName = "WatcherServiceDetail")]
public WatcherServiceDetailCollection<TWatcherServiceDetailElement> WatcherServiceDetails
I'm aware that type parameters aren't allowed for attributes and that's what I want to know how to do.
© Stack Overflow or respective owner