你能帮我配置一下Spring.Net,在对象属性中注入一个预先定义的哈希表吗?
我做过这样的事情:
<object name="myHashtable" type="Hashtable">
<map>
<entry key="key1" value="value1" />
<entry key="key2" value="value2" />
</map>
</object>
但似乎MAP节点不存在!
解决
确切的配置是:
<object id="myHashtable" type="System.Collections.Hashtable">
<constructor-arg>
<dictionary key-type="decimal?" value-type="int" merge="0">
<entry key="1" value="31" />
<entry key="2" value="32" />
<entry key="3" value="33" />
<entry key="4" value="34" />
</dictionary>
</constructor-arg>
</object>
答案 0 :(得分:2)
使用IDictionary
作为构造函数创建一个哈希表,例如:
<object id="MyObject" type="MyClass">
<property name="MyHashTable">
<object type="System.Collections.Hashtable, mscorlib">
<constructor-arg name="d">
<dictionary>
<entry key="key1" value="value1" />
<entry key="key2" value="value2" />
</dictionary>
</constructor-arg>
</object>
</property>
</object>