aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects/Container.cs
blob: 360eee5161f490e9338a478d6340de81279356b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Xml.Serialization;
using System.Reflection;
using OpenTK.Input;
using System.ComponentModel;
using System.Linq;

namespace Crow
{
    public class Container : PrivateContainer, IXmlSerializable
    {
		#region CTOR
		public Container()
			: base()
		{
		}
		public Container(Rectangle _bounds)
			: base(_bounds)
		{
		}
		#endregion

		[XmlIgnore]
		public GraphicObject Child {
			get { return child; }
			set { child = value; }
		}
		public virtual T SetChild<T> (T _child)
		{
			return base.SetChild (_child);
		}

		#region IXmlSerializable

        public override System.Xml.Schema.XmlSchema GetSchema()
        {
            return null;
        }
        public override void ReadXml(System.Xml.XmlReader reader)
        {
			//only read attributes in GraphicObject IXmlReader implementation
            base.ReadXml(reader);


            using (System.Xml.XmlReader subTree = reader.ReadSubtree())
            {
                subTree.Read(); //skip current node
                subTree.Read(); //read first child

                if (!subTree.IsStartElement())
                    return;

                Type t = Type.GetType("Crow." + subTree.Name);
                GraphicObject go = (GraphicObject)Activator.CreateInstance(t);                                

                (go as IXmlSerializable).ReadXml(subTree);
                
                SetChild(go);

                subTree.Read();//closing tag
            }
        }
        public override void WriteXml(System.Xml.XmlWriter writer)
        {
            base.WriteXml(writer);

            if (Child == null)
                return;

            writer.WriteStartElement(Child.GetType().Name);
            (Child as IXmlSerializable).WriteXml(writer);
            writer.WriteEndElement();
        }
    
		#endregion
	}
}