开发者

serialize array of object

[Serializable()]
public class A
{

        [XmlArr开发者_如何学PythonayAttribute("Item")]
        public  List<B> items;
}

[Serializable()]
[XmlType(TypeName = "Item")]
public class B
{

}

After serialization, I found I have something like

<Item>
   <Item> **** </Item>
   <Item> **** </Item>
    *****
</item>

But I only want

 <Item> **** </Item>
 <Item> **** </Item>

How to get it?


public class A
{
    [XmlElement("Item")]
    public List<B> items;
}

public class B
{

}

Notice that you don't need the [Serializable] attribute. It is used only for binary serialization and ignored by XmlSerializer which is what I suspect you are using even if this should have been clearly stated in your question. Also for better encapsulation I would recommend you using properties instead of fields. And another remark: the standard naming convention in C# dictates that property names should start with a capital letter.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜