示例#1
0
        /// <summary>
        /// Serializes this object into xml.
        /// The underlying data structure is a flat tree, using the type SNode
        /// </summary>
        /// <param name="reader"></param>
        public void ReadXml(XmlReader reader)
        {
            List <SNode <T> > listnodes = new List <SNode <T> >();

            reader.ReadStartElement("Root");
            reader.MoveToAttribute("size");
            int count = 0;

            int.TryParse(reader.Value, out count);


            var ser1 = new XmlSerializer(typeof(SNode <T>));

            reader.ReadStartElement();
            for (int i = 0; i < count; ++i)
            {
                var node = new SNode <T>();
                node = (SNode <T>)ser1.Deserialize(reader);
                listnodes.Add(node);
            }


            reader.ReadEndElement();


            var tnodes = new List <Node <T> >();

            foreach (var tn in listnodes)
            {
                var x = new Node <T>(tn.name);
                x.uuid = tn.uuid;
                x.data = tn.data;

                if (tn.parent != "")
                {
                    x.parent = (from y in tnodes where y.uuid == tn.parent select y).First();
                }

                tnodes.Add(x);
            }


            foreach (var tn in tnodes)
            {
                tn.children = (from r in tnodes where r.parent != null && r.parent.uuid == tn.uuid select r).ToArray().ToList();
            }

            this.name     = tnodes.First().name;
            this.uuid     = tnodes.First().uuid;
            this.parent   = tnodes.First().parent;
            this.children = tnodes.First().children;
            this.data     = tnodes.First().data;
        }
示例#2
0
        public bool Equals(SNode <T> node)
        {
            if (ReferenceEquals(node, null))
            {
                return(false);
            }
            if (ReferenceEquals(this, node))
            {
                return(true);
            }

            return(this.uuid == node.uuid);
        }