c# – 包含Spring.Net中的通用字典的通用字典
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 包含Spring.Net中的通用字典的通用字典,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1755字,纯文字阅读大概需要3分钟。
内容图文
![c# – 包含Spring.Net中的通用字典的通用字典](/upload/InfoBanner/zyjiaocheng/815/29ccf919a8d54734ad2d6c4b0c801ba8.jpg)
我有一个包含属性的对象:
public Dictionary<string, Dictionary<string, List<ContextMenuItemModel>>> ContextMenuModel { get; set; }
如何使用Spring.Net配置此属性?
解决方法:
好吧,在xml中配置这个并不漂亮,考虑将Spring.Net代码配置切换到configure your spring context in C#.
无论如何,要在xml中执行此操作,您将使用通用.net集合的构造函数.例如,List< T>采用IList< T>构造函数,因此您可以按如下方式配置字符串列表:
<object id="list1" type="System.Collections.Generic.List<string>">
<constructor-arg>
<list element-type="string">
<value>abc</value>
<value>def</value>
</list>
</constructor-arg>
</object>
请注意,在xml中你必须使用& lt;,因为使用<是不合法的xml.设置通用集合值在in the Spring.net docs中讨论.
通用字典< string,System.Collections.Generic.List< string>>可以以类似的方式配置,这也在this answer中讨论:
<object id="dic1" type="System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>>">
<constructor-arg>
<dictionary key-type="string" value-type="System.Collections.Generic.List<string>">
<entry key="keyToList1" value-ref="list1" />
<entry key="keyToList2" value-ref="list2" />
</dictionary>
</constructor-arg>
</object>
你可能会看到下一个即将到来:
<object id="dic0" type="System.Collections.Generic.Dictionary<string, System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>>>">
<constructor-arg>
<dictionary key-type="string" value-type="System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<string>>">
<entry key="keyToDic1 " value-ref="dic1" />
</dictionary>
</constructor-arg>
</object>
哪个可以注射:
<object id="MyObject" type="MyNamespace.MyClass, MyAssembly">
<property name="ContextMenuModel" ref="dic0" />
</object>
这不是很漂亮,但你可以稍微improve the readability of your xml using type aliases.
内容总结
以上是互联网集市为您收集整理的c# – 包含Spring.Net中的通用字典的通用字典全部内容,希望文章能够帮你解决c# – 包含Spring.Net中的通用字典的通用字典所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。