[Mono-list] XmlRoot attribute is ignored, why?

Ympostor Ympostor at clix.pt
Mon Aug 28 18:26:19 EDT 2006


Hello.

I have a code-snippet that shows an example where XmlRoot attribute is
used three times but it is only applied once. Any clues? Thanks in advance:


using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.Xml;
using System.IO;

namespace XmlRootTest
{
	[XmlRoot("This_works")]
	public class MyList : List<MySecondList>{
	
		private string myField;
		public string MyField {
			get { return this.myField; }
			set { this.myField = value; }
		}
	}
	
	[XmlRoot("This_does_not_work")]
	public class MySecondList : List<MyClass>{
		private string myField;
		public string MyField {
			get { return this.myField; }
			set { this.myField = value; }
		}
	}
	
	[XmlRoot("Neither_this_one")]
	public class MyClass {
	
		private string myField;
		public string MyField {
			get { return this.myField; }
			set { this.myField = value; }
		}
	}
	
	public class Program
	{
		
		public static void Main()
		{
	
			MyClass oMyObject = new MyClass();
			oMyObject.MyField = "test4";

			MyClass oMyObject2 = new MyClass();
			oMyObject2.MyField = "test5";
			
			MyClass oMyObject3 = new MyClass();
			oMyObject3.MyField = "test6";
			
		
			MyList oList = new MyList();
			oList.MyField = "test";
			MySecondList oList2 = new MySecondList();
			oList2.MyField = "test2";
			
			oList2.Add(oMyObject);
			oList2.Add(oMyObject3);
			
			MySecondList oList3 = new MySecondList();
			oList3.MyField = "test3";
			oList3.Add(oMyObject2);
			oList3.Add(oMyObject);
			
			oList.Add(oList2);
			oList.Add(oList3);
		

			XmlSerializer oSer = new XmlSerializer(typeof(MyList));
			TextWriter oWriter = new StreamWriter("list.xml");
			oSer.Serialize(oWriter, oList);
			oWriter.Close();
		}
	}
}


-- 



More information about the Mono-list mailing list