arraysmultidimensional-arrayspring.net

Spring.Net: How to initialise a multi-dimensional array?


I want to initialise a multi-dimensional array with spring.net. How to define the array?

I tried this

<object type="string[][][]" id="my_array" name="my_array">
  <constructor-arg>
    <list>
      <value>
      ["A", "B", "C"],
      ["a", "b", "c"],
      ["E", "F", "G"]
      </value>
      <value>
      ["X", "Y", "Z"],
      ["x", "y", "z"],
      ["U", "V", "W"]
      </value>
    </list>
  </constructor-arg>
</object>

but got a type exception. I also tried it with an System.Collection.ArrayList, but this didn't work either.


Solution

  • ArrayList configured as follows works for me. Tried and tested :) :

    <object id="my_array" name="my_array" type="System.Collections.ArrayList">
        <constructor-arg>
          <list>
            <list>
              <list>
                <value>"A"</value>
                <value>"B"</value>
                <value>"C"</value>
              </list>
              <list>
                <value>"a"</value>
                <value>"b"</value>
                <value>"c"</value>
              </list>
              <list>
                <value>"E"</value>
                <value>"F"</value>
                <value>"G"</value>
              </list>
            </list>
            <list>
                <list>
                  <value>"X"</value>
                  <value>"Y"</value>
                  <value>"Z"</value>
                </list>
                <list>
                  <value>"x"</value>
                  <value>"y"</value>
                  <value>"z"</value>
                </list>
                <list>
                  <value>"U"</value>
                  <value>"V"</value>
                  <value>"W"</value>
                </list>
              </list>
          </list>
          </constructor-arg>
      </object>
    

    There's ways to use a string [][][] if you want using <List element-type="String[]"...... Also, there's apparently a way to use comma separated values for list elements to make the above answer smaller, but I can't get it to work. Something like:

    <list>
      <value>"a","b","c"</value>
    </list>