开发者

XML Serialize property with datatype as Array in C# .net

开发者 https://www.devze.com 2023-02-09 14:40 出处:网络
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,

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消