How do I create and populate a Dictionary<string,Object> using Unity's xml configuration?

谁说胖子不能爱 提交于 2019-12-02 07:06:32

This works

<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">

    <alias alias="MyStuffObject" type="MyStuffObject, MyStuff"/>
    <!-- dictionary stuff -->
    <alias alias="IDictionaryOfStuff" type="System.Collections.Generic.IDictionary`2[[System.String, mscorlib],[MyStuffObject, MyStuff]], mscorlib"/>
    <alias alias="DictionaryOfStuff" type="System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[MyStuffObject, MyStuff]], mscorlib"/>

    <!-- Containers -->
    <container name="Stuff">

        <register type="IDictionaryOfStuff" mapTo="DictionaryOfStuff" name="dictionaryOfStuff">
            <constructor />
            <method name="Add">
                <param name="key" type="System.String" value="Cool_Key"/>
                <param name="value" type="IClinicalDocumentParser" dependencyName="coolStuffObject"/>
            </method>
        </register>

        <register type="MyStuffObject" mapTo="MyStuffObject" name="coolStuffObject" />
    </container>
</unity>

You would have to create some sort of parsing system.

You can use the XML system in .Net to parse the XML code and then add it to the dictionary by doing dictionary.Add();

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!