代码改变世界

[C#]将一个类序列化为XML

2010-06-04 13:43  轩脉刃  阅读(609)  评论(0编辑  收藏  举报

在C#中要想将一个类序列化为XML,则使用XmlSerializer类:

 

代码
XmlSerializer serializer = new XmlSerializer(typeof(PurchaseOrder));
TextWriter writer
= new StreamWriter(filename);
PurchaseOrder po
=new PurchaseOrder();
// Serialize the purchase order, and close the TextWriter.
serializer.Serialize(writer, po);
writer.Close();

 

可以参考WebService生成代理类的结构