Spring.Net 中包含通用列表值的通用字典
我有一个包含属性的对象:
public Dictionary<string, List<Hotel>> CityHotels { get; set; }
How do I use Spring.Net to configure this property?
我尝试这样做:
<property name="CityHotels">
<dictionary key-type="string" value-type="System.Collections.Generic.List<MyNameSpace.Hotel, MyAssembly>" >
<entry key="SYD">
<list element-type="MyNameSpace.Hotel, MyAssembly">
</list>
</entry>
</dictionary>
</property>
但没有成功:
创建上下文“spring.root”时出错:无法从字符串值“System.Collections.Generic.List`2”加载类型。
我做错了什么?
在我尝试使用 Spring.Net 设置 ILookup,所以如果有办法做到这一点,那就可以以更干净的方式解决我的问题。
I have an object that contains a property:
public Dictionary<string, List<Hotel>> CityHotels { get; set; }
How do I use Spring.Net to configure this property?
I tried doing this:
<property name="CityHotels">
<dictionary key-type="string" value-type="System.Collections.Generic.List<MyNameSpace.Hotel, MyAssembly>" >
<entry key="SYD">
<list element-type="MyNameSpace.Hotel, MyAssembly">
</list>
</entry>
</dictionary>
</property>
but it was unsuccessful:
Error creating context 'spring.root': Could not load type from string value 'System.Collections.Generic.List`2'.
What am I doing wrong?
This convoluted mess came about after I unsuccessfully tried to use Spring.Net to set a property of type ILookup, so if there is a way to do that, that would solve my problem in a cleaner way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
spring配置的解决方案:
在字典的值类型中,您不需要添加MyAssembly,而是为
System.Collections.Generic.List
添加mscorlib。我希望这会对您有所帮助!
Solution for the spring config:
In the value-type of the dictionary you don't need to add MyAssembly but mscorlib for
System.Collections.Generic.List
.I hope this will help you!
请参阅http://www.springframework。 net/doc-latest/reference/html/objects.html#objects-creation-generic-types
See http://www.springframework.net/doc-latest/reference/html/objects.html#objects-creation-generic-types