using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
class OrderedItem
{
public string ItemName;
public string Description;
public decimal UnitPrice;
public int Quantity;
public decimal LineTotal;
public void Calculate()
{
LineTotal = UnitPrice * Quantity;
}
}
public class Test{
public static void Main()
{
XmlSerializer serializer = new XmlSerializer(typeof(OrderedItem));
OrderedItem i = new OrderedItem();
i.ItemName = "A";
i.Description = "test";
i.Quantity = 10;
i.UnitPrice = (decimal) 2.30;
i.Calculate();
Stream fs = new FileStream("c:\\a.xml", FileMode.Create);
XmlWriter writer = new XmlTextWriter(fs, Encoding.Unicode);
serializer.Serialize(writer, i);
writer.Close();
}
}
|