Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Xml / System / Xml / XPath / XPathNavigatorKeyComparer.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="XmlNavigatorReader.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
7
8 using System.IO;
9 using System.Xml.Schema;
10 using System.Collections;
11 using System.Diagnostics;
12 using MS.Internal.Xml.Cache;
13
14 namespace System.Xml.XPath {
15     internal class XPathNavigatorKeyComparer : IEqualityComparer {
16         bool IEqualityComparer.Equals( Object obj1, Object obj2 ) {
17             XPathNavigator nav1 = obj1 as XPathNavigator;
18             XPathNavigator nav2 = obj2 as XPathNavigator;
19             if( ( nav1 != null ) && ( nav2 != null ) ) {
20                 if( nav1.IsSamePosition( nav2 ) )
21                     return true;
22             }
23             return false;
24         }
25
26         int IEqualityComparer.GetHashCode ( Object obj ) {
27             int hashCode;
28             XPathNavigator nav;
29             XPathDocumentNavigator xpdocNav;
30
31             if (obj == null) {
32                 throw new ArgumentNullException("obj");
33             }
34             else if ( null != (xpdocNav = obj as XPathDocumentNavigator) ) {
35                 hashCode = xpdocNav.GetPositionHashCode();
36             }
37             else if( null != (nav = obj as XPathNavigator) ) {
38                 Object underlyingObject = nav.UnderlyingObject;
39                 if (underlyingObject != null) {
40                     hashCode = underlyingObject.GetHashCode();
41                 }
42                 else {
43                     hashCode = (int)nav.NodeType;
44                     hashCode ^= nav.LocalName.GetHashCode();
45                     hashCode ^= nav.Prefix.GetHashCode();
46                     hashCode ^= nav.NamespaceURI.GetHashCode();
47                 }
48             } 
49             else {
50                 hashCode = obj.GetHashCode();
51             }
52             return hashCode;
53         }
54     }
55 }