我无法在windsor xml文件中定义IDictionary<string,List<string>>
我的班级(C#):
public class myService
{
public IDictionary<string, List<string>> Apis { get; set; }
}
windsor配置文件:
<component id="myService" type="Test.Service.myService, Test.Service">
<parameters>
<Apis>
<dictionary>
<entry key="api1">${api}</entry>
</dictionary>
</Apis>
</parameters>
</component>
<component id="api" type="System.Array, mscorlib">
<array>
<item>a</item>
<item>b</item>
</array>
</component>
我也尝试过:
<component id="api" type="System.Collections.Generic.List`1[[System.String, mscorlib]], mscorlib">
<parameters>
<collection>
<array>
<item>a</item>
<item>b</item>
</array>
</collection>
</parameters>
</component>
我能用windsor配置吗? 谢谢
答案 0 :(得分:1)
我用来初始化词典的策略。
public class MyDictionary : Dictionary<int, string> { public MyDictionary(Dictionary<int, string> source) { foreach (var entry in source) { Add(entry.Key, entry.Value); } } }
<component id="DictionaryComponent" type="MyDictionary, MyAssembly"> <parameters> <source> <dictionary> <entry key="2012">last year</entry> <entry key="2013">this year</entry> </dictionary> </source> </parameters> </component>