自定义配置部分中的泛型
我尝试制作一个自定义配置类,如下所示:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要指定类型的全名。
这包括泛型类型的全名,后跟 ` 以及泛型类型参数的数量,其中类型参数的全名位于 [...] 中,
例如
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.
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