2003-02-03 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.XML / System.Xml / XmlLinkedNode.cs
index 1fd4d12fdb0621d69e7caadaab4c4397dba15c9d..cc6be542fd446b6cd69324dfa922a9fbb33b7789 100644 (file)
@@ -1,3 +1,13 @@
+//
+// System.Xml.XmlLinkedNode
+//
+// Authors:
+//   Jason Diamond <jason@injektilo.org>
+//   Kral Ferch <kral_ferch@hotmail.com>
+//
+// (C) 2002 Jason Diamond, Kral Ferch
+//
+
 using System;
 
 namespace System.Xml
@@ -5,20 +15,26 @@ namespace System.Xml
        public abstract class XmlLinkedNode : XmlNode
        {
                #region Fields
+
                XmlLinkedNode nextSibling;
+               XmlLinkedNode lastLinkedChild;
 
                #endregion
 
                #region Constructors
-               protected internal XmlLinkedNode(XmlDocument doc) : base(doc) { }
+               internal XmlLinkedNode(XmlDocument doc) : base(doc) { }
 
                #endregion
 
-               #region Properties              
+               #region Properties
+
                public override XmlNode NextSibling
                {
                        get {
-                               if (Object.ReferenceEquals(nextSibling, ParentNode.LastLinkedChild.NextLinkedSibling) == false) {
+                               if(ParentNode == null) {
+                                       return null;
+                               }
+                               else if (Object.ReferenceEquals(nextSibling, ParentNode.LastLinkedChild.NextLinkedSibling) == false) {
                                        return nextSibling;
                                }
                                else {
@@ -33,14 +49,29 @@ namespace System.Xml
                        set { nextSibling = value; }
                }
 
-               [MonoTODO]
                public override XmlNode PreviousSibling
                {
                        get {
-                               throw new NotImplementedException ();
+                               if (ParentNode != null) {
+                                       XmlNode node = ParentNode.FirstChild;
+                                       if (node != this) {
+                                               do {
+                                                       if (node.NextSibling == this)
+                                                               return node;
+                                               } while ((node = node.NextSibling) != null);
+                                       }                                       
+                               }
+                               return null;
                        }
                }
 
+               // copied this way from XmlElement
+               internal override XmlLinkedNode LastLinkedChild
+               {
+                       get { return lastLinkedChild; }
+                       set { lastLinkedChild = value; }
+               }
+
                #endregion
        }
 }