using System; using System.Collections.Generic; using System.Collections; using System.Text; using System.Xml; using System.Xml.Serialization; using System.IO; namespace test { class WorldManager { private ArrayList Worlds = new ArrayList(); public WorldManager() { } public void Add(World w) { Worlds.Add( w ); } public void Remove(World w) { Worlds.Remove( w ); } public World Find(string name) { for(int x = 0; x < Worlds.Count; x++) { World w = ((World)Worlds[x]); if(w.name == name) { return w; } } return null; } public void Save( string filename ) { XmlSerializer xmlser = new XmlSerializer( typeof( ArrayList ) , null, new Type[]{ typeof( World ), typeof( Tile ), typeof( Object ) }, new XmlRootAttribute("WorldList"), "Something"); TextWriter file = new StreamWriter(filename); xmlser.Serialize( file, Worlds ); } public void Load( string filename ) { XmlSerializer xmlser = new XmlSerializer( typeof( ArrayList ) , null, new Type[]{ typeof( World ), typeof( Tile ), typeof( Object ) }, new XmlRootAttribute("WorldList"), "Something"); TextReader file = new StreamReader(filename); Worlds = (ArrayList) xmlser.Deserialize( file ); } } public class World { public World() { } public World(string name) { this.name = name; Tile t = new Tile(); Object o = new Object(); t.id = 1; o.name = "object"; tiles.Add(t); objects.Add(o); } public string name; public ArrayList tiles = new ArrayList(); public ArrayList objects = new ArrayList(); } public class Tile { public int id; } public class Object { public string name; } class Program { public static void Main(string[] args) { WorldManager wm = new WorldManager(); World w = new World("Namek"); wm.Add(w); wm.Save("Worlds.xml"); } } }