2010-05-05 72 views
1

我試圖使現場發生的像這樣的自定義配置類:泛型的自定義配置節

WatcherServiceInfoSection<TWatcherServiceDetailElement> 

其中TWatcherServiceDetailElement是裏面一個ConfigurationElement

現在,當我打電話類型的ConfigSections區域的AppConfig的我得到的錯誤:

An error occurred creating the configuration section handler for WatcherServiceInfo: 
Could not load type 'Library.Common.Utilities.ConfigurationHandler.WatcherServiceInfoSection<ASNDPService.Configuration.WatcherServiceDetailElement>' from assembly 

是我在做什麼可能?我可以在自定義節元素的type屬性中使用泛型類型嗎?

編輯

此外,ConfigurationElementCollection對象怎麼樣?就像上面的例子中,我怎麼可能做一個

[ConfigurationProperty("WatcherServiceDetails", IsRequired = true, 
IsDefaultCollection = true)] 
[ConfigurationCollection(typeof(TWatcherServiceDetailElement), AddItemName = "WatcherServiceDetail")] 
public WatcherServiceDetailCollection<TWatcherServiceDetailElement> WatcherServiceDetails 

我知道,類型參數是不允許的屬性,這就是我想知道怎麼做。

回答

3

您需要指定類型的全名。

這包括一般類型後跟一個`和通用類型參數與所述類型參數的全名在數的全名[...]

例如

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

我會盡量掀起一個更合理的例子。

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

也看到Including a generic class in Unity App.Config file