本文介绍了在Spring.Net中包含通用列表值的通用字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含属性的对象:
I have an object that contains a property:
public Dictionary<string, List<Hotel>> CityHotels { get; set; }
如何使用Spring.Net配置此属性?
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.Net设置类型,所以如果有办法做到这一点,那将解决我的问题
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.
推荐答案
弹簧配置的解决方案:
<object id="HotelFinder" type="MyNameSpace.HotelFinder, MyAssembly">
<property name="CityHotels">
<dictionary key-type="string" value-type="System.Collections.Generic.List<MyNameSpace.Hotel>, mscorlib">
<entry key="London" value-ref="hotelsLondon" />
</dictionary>
</property>
</object>
<object id="hotelsLondon" type="System.Collections.Generic.List<MyNameSpace.Hotel>, mscorlib">
<constructor-arg>
<list element-type="MyNameSpace.Hotel, MyAssembly">
<ref object="hotelLonden1"/>
<ref object="hotelLonden2"/>
<ref object="hotelLonden3"/>
<ref object="hotelLonden4"/>
</list>
</constructor-arg>
</object>
<object id="hotelLonden1" type="MyNameSpace.Hotel, MyAssembly" />
<object id="hotelLonden2" type="MyNameSpace.Hotel, MyAssembly" />
<object id="hotelLonden3" type="MyNameSpace.Hotel, MyAssembly" />
<object id="hotelLonden4" type="MyNameSpace.Hotel, MyAssembly" />
在字典的值类型中,您不需要添加MyAssembly,但mscorlib System.Collections.Generic.List
。
In the value-type of the dictionary you don't need to add MyAssembly but mscorlib for System.Collections.Generic.List
.
我希望这会帮助你!
这篇关于在Spring.Net中包含通用列表值的通用字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!