.net XmlSerializer and multidimensional arrays

I am implementing a program that acts as a client for some existing software. The protocol is schema-defined XML

and includes multidimensional arrays.

The .net XmlSerializer cannot handle them - this is a known issue.

Is there a way to extend XmlSerializer

so that I can implement handling for this, or is there a complete (free or commercial) replacement for XmlSerializer

that that can handle multidimensional arrays?

SharpSerializer

doesn't seem to generate XML schema but uses native serialization format.

I guess I can use a sgen.exe

serializer to generate code and then manually edit it manually to add the necessary processing, but I would like to avoid that.

+3


source to share


1 answer


If you have control to change your schema, you can try using jagged arrays instead of multidimensional arrays.

string[][]

instead string[,]

or use something like List<List<T>>



You can create your own custom class that flattens a multidimensional array.

Alternatively, use XmlIgnore in your class, flatten multidimensional array into standard array (as suggested here by Mark Gravell )

[XmlIgnore]
public int[, ,] Data { get; set; }

[XmlElement("Data"), Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public int[] DataDto
{
    get { /* flatten from Data */ }
    set { /* expand into Data */ }
}

      

0


source







All Articles