using System;
using System.IO;
using System.Xml.Serialization;
using System.Collections;
using System.Xml;
public class MyClass
{
[XmlElement(typeof(MyTestClass)),
XmlElement(typeof(int)),
XmlElement(typeof(string)),
XmlElement(typeof(string[]))]
public ArrayList MyContainer;
}
public class MyTestClass
{
public string Name;
}
public class Test
{
public static void Main()
{
string sFile = "OverrideElement.xml";
Test t = new Test();
t.SerializeObject(sFile);
Console.WriteLine("enter to deserialize");
Console.ReadLine();
t.DeserializeObject(sFile);
}
public void SerializeObject(string filename)
{
XmlSerializer xSer = new XmlSerializer(typeof(MyClass));
MyClass myMyClass = new MyClass();
myMyClass.MyContainer = new ArrayList();
MyTestClass myMyTestClass = new MyTestClass();
myMyTestClass.Name = "MyMyTestClass";
myMyClass.MyContainer.Add(myMyTestClass);
myMyClass.MyContainer.Add("String");
myMyClass.MyContainer.Add(100);
string[] slist = {"hello","world"};
myMyClass.MyContainer.Add(slist);
TextWriter writer = new StreamWriter(filename);
xSer.Serialize(writer, myMyClass);
writer.Close();
}
public void DeserializeObject(string filename)
{
XmlSerializer xSer = new XmlSerializer(typeof(MyClass));