Merge pull request #950 from ermshiperete/bug-xamarin-2787
[mono.git] / mcs / class / System.Xml.Linq / System.Xml.Linq / XNodeDocumentOrderComparer.cs
index e6df58e220139e1ff4876768149d1046aadc3b56..296d4a261d85f61bcac2aba0410084ce5af7497a 100644 (file)
@@ -48,9 +48,9 @@ namespace System.Xml.Linq
                        Following
                }
 
-               public int Compare (XNode n1, XNode n2)
+               public int Compare (XNode x, XNode y)
                {
-                       switch (CompareCore (n1, n2)) {
+                       switch (CompareCore (x,y)) {
                        case CompareResult.Same:
                                return 0;
                        case CompareResult.Random:
@@ -116,19 +116,19 @@ namespace System.Xml.Linq
                        switch (ret) {
                        case CompareResult.Same:
                                // n1 and n2 are sibling each other.
-                               return CompareSibling (n1, n2);
+                               return CompareSibling (n1, n2, CompareResult.Same);
                        case CompareResult.Child:
-                               return CompareSibling (n1, n2.Owner);
+                               return CompareSibling (n1, n2.Owner, CompareResult.Child);
                        case CompareResult.Parent:
-                               return CompareSibling (n1.Owner, n2);
+                               return CompareSibling (n1.Owner, n2, CompareResult.Parent);
                        case CompareResult.Descendant:
                                for (XNode i2 = n2; ; i2 = i2.Owner)
                                        if (i2.Owner == n1.Owner)
-                                               return CompareSibling (n1, i2);
+                                               return CompareSibling (n1, i2, CompareResult.Descendant);
                        case CompareResult.Ancestor:
                                for (XNode i1 = n1; ; i1 = i1.Owner)
                                        if (i1.Owner == n2.Owner)
-                                               return CompareSibling (i1, n2);
+                                               return CompareSibling (i1, n2, CompareResult.Ancestor);
                        default:
                                return ret;
                        }
@@ -136,8 +136,11 @@ namespace System.Xml.Linq
 
                // results are returned as following/preceding, as it is also
                // used for comparing parents.
-               CompareResult CompareSibling (XNode n1, XNode n2)
+               CompareResult CompareSibling (XNode n1, XNode n2, CompareResult forSameValue)
                {
+                       if (n1 == n2)
+                               return forSameValue;
+
                        for (XNode n = n1.NextNode; n != null; n = n.NextNode)
                                if (n == n2)
                                        return CompareResult.Following;