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

倾然丶 夕夏残阳落幕 提交于 2019-12-20 05:13:07

问题


How do I create and populate a Dictionary using Unity's xml configuration?

I need to create a Dictionary and populate the objects using dependency references in unity.

How can I accomplish this?


回答1:


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>



回答2:


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();



来源:https://stackoverflow.com/questions/5597492/how-do-i-create-and-populate-a-dictionarystring-object-using-unitys-xml-confi

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