自定义配置部分中的泛型

发布于 2024-08-31 11:28:57 字数 1048 浏览 2 评论 0原文

我尝试制作一个自定义配置类,如下所示:

WatcherServiceInfoSection<TWatcherServiceDetailElement>

其中 TWatcherServiceDetailElement 是其中的一个 ConfigurationElement

现在,当我调用 AppConfig 的 ConfigSections 区域中的类型时,我收到错误:

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

我知道属性不允许使用类型参数,这就是我想知道该怎么做。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

决绝 2024-09-07 11:28:57

您需要指定类型的全名。

这包括泛型类型的全名,后跟 ` 以及泛型类型参数的数量,其中类型参数的全名位于 [...] 中,

例如

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

I会尝试举出一个更合理的例子。

请参阅http://theburningmonk。 com/2010/03/castle-windsor-tips-specifying-generic-types-in-config-file/

另请参阅 在 Unity App.Config 文件中包含通用类

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文