5

I'm implementing a program which acts as a client to some existing software. The protocol is defined using an XML schema, and it includes multidimensional arrays.

The .net XmlSerializer cannot handle those - it's a known issue.

Is there a way to extend XmlSerializer so I can implement handling for this, or is there a full (free or commercial) replacement for XmlSerializer that can handle multidimensional arrays?

SharpSerializer does not seem to create schema defined XML, but uses it's own serialization format.

I guess I can use sgen.exe to generate the serializer code, and then edit that manually afterwards to add the necessary handling, but I would like to avoid that.

1
  • You could add a property to your class which gives you a string of your array field. Ignore the array field with XmlIgnore and make the property serializable. Commented Jun 12, 2015 at 8:15

1 Answer 1

1

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

string[][] instead of string[,]

or use something like List<List<T>>

You can create your own custom class which flattens the multidimensional array.

Alternatively, use XmlIgnore on your class, flatten the multidimensional array into a standard array (as proposed here by Marc 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 */ }
}
Sign up to request clarification or add additional context in comments.

2 Comments

What sort of thing goes in those get and set braces?
I've answered my own comment here: stackoverflow.com/questions/553824/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.