XML Serialize property with datatype as Array in C# .net
I have Property
public Array Data
{
get;
set;
}
But I can't serialize it since type Array is not serializable, any Idea how can I achieve this,
Th开发者_开发知识库anx
You need to give it more information; the simplest it to give it the typed array - for example, with a string array:
public string[] Data {get;set;}
It may (unsure) be possible to send untyped single-dimenstion arrays using [XmlArray]
and [XmlArrayItem]
to specify the type - but by the time you've done that a typed array would have been easier. I doubt that multi-dimensional arrays are supported.
You can use a List<T>
where T
is the type of object in your array. Then it will be able to serialize because it knows the Type of object. I believe it serializes like this:
<ArrayOfType>
<Type>
<X>value</X>
<Y>value</Y>
</Type>
<Type>
<X>value</X>
<Y>value</Y>
</Type>
</ArrayOfType>
精彩评论