I have an xml serialization question i was hoping someone would know.
If you have a class member that is an array...
[XmlArrayItem("Number")]
public List<int> MyNumbers
{
get {...}
set {...}
}
this will get serialized as...
<MyNumbers>
<Number>1</Number>
<Number>2</Number>
<Number>3</Number>
</MyNumbers>
is it possible to have this serialize as a comma-delimited string instead?
i.e...
<MyNumbers>1,2,3</MyNumbers>
if so...what is the best way?
Well I think the only way to do it is to override IXMLSerializable and write
the value as you want it.
My question then becomes...how does this affect using the type in a wcf
contract?
It is marked [serializable] also. I am a little confused on how the
ISerializable and IXMLSerializable interrelate.
Do you have to implement both for binary and xml if you want the object to
be serialized into xml and also binary?
> I have an xml serialization question i was hoping someone would know.
>
[quoted text clipped - 21 lines]
>
> if so...what is the best way?
Ollie Riches - 11 Mar 2008 19:55 GMT
> Well I think the only way to do it is to override IXMLSerializable and write
> the value as you want it.
[quoted text clipped - 35 lines]
>
> - Show quoted text -
Another way is to have another set of properties - the getter would
output the numbers as the comma seperated list and the setter would
process the comma seperated list of numbers...
[XmlIgnore())]
public List<int> MyNumbers
{
get {...}
set {...}
}
[XmlElement(Name = "MyNumbers")]
public string MyNumbersAsCSV
{
get {...}
set {...}
}
HTH
Ollie Riches