2002-12-21 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
[mono.git] / mcs / class / System.XML / System.Xml / XmlLinkedNode.cs
1 //
2 // System.Xml.XmlLinkedNode
3 //
4 // Authors:
5 //   Jason Diamond <jason@injektilo.org>
6 //   Kral Ferch <kral_ferch@hotmail.com>
7 //
8 // (C) 2002 Jason Diamond, Kral Ferch
9 //
10
11 using System;
12
13 namespace System.Xml
14 {
15         public abstract class XmlLinkedNode : XmlNode
16         {
17                 #region Fields
18
19                 XmlLinkedNode nextSibling;
20                 XmlLinkedNode lastLinkedChild;
21
22                 #endregion
23
24                 #region Constructors
25                 internal XmlLinkedNode(XmlDocument doc) : base(doc) { }
26
27                 #endregion
28
29                 #region Properties
30
31                 public override XmlNode NextSibling
32                 {
33                         get {
34                                 if(ParentNode == null) {
35                                         return null;
36                                 }
37                                 else if (Object.ReferenceEquals(nextSibling, ParentNode.LastLinkedChild.NextLinkedSibling) == false) {
38                                         return nextSibling;
39                                 }
40                                 else {
41                                         return null;
42                                 }
43                         }
44                 }
45
46                 internal XmlLinkedNode NextLinkedSibling
47                 {
48                         get { return nextSibling; }
49                         set { nextSibling = value; }
50                 }
51
52                 public override XmlNode PreviousSibling
53                 {
54                         get {
55                                 if (ParentNode != null) {
56                                         XmlNode node = ParentNode.FirstChild;
57                                         if (node != this) {
58                                                 do {
59                                                         if (node.NextSibling == this)
60                                                                 return node;
61                                                 } while ((node = node.NextSibling) != null);
62                                         }                                       
63                                 }
64                                 return null;
65                         }
66                 }
67
68                 // copied this way from XmlElement
69                 internal override XmlLinkedNode LastLinkedChild
70                 {
71                         get { return lastLinkedChild; }
72                         set { lastLinkedChild = value; }
73                 }
74
75                 #endregion
76         }
77 }