开发者

Generics in custom configuration sections

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.WatcherServiceInfoSecti开发者_如何学运维on<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.


you need to specify the full name of the type.

This includes the full name of the generic type followed by a ` and the number of generic type parameters with the full names of the type parameters in [...]

e.g.

<component id="FooRetriever"
           service="Namespace.IRetrievable`2[[Namespace.Foo, Assembly],[System.String]], Assembly"
           type="Namespace.FooRetriever, Assembly"/>

I will try to whip up a more reasonable example.

see http://theburningmonk.com/2010/03/castle-windsor-tips-specifying-generic-types-in-config-file/

also see Including a generic class in Unity App.Config file

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜