The Labs \ Source Viewer \ SSCLI \ System.Xml.Schema \ ChameleonKey

  1. //------------------------------------------------------------------------------
  2. // <copyright file="XmlSchemaExternal.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. // <owner current="true" primary="true">priyal</owner>
  15. //------------------------------------------------------------------------------
  16. namespace System.Xml.Schema
  17. {
  18.    
  19.     using System.Collections;
  20.     using System.ComponentModel;
  21.     using System.Xml.Serialization;
  22.    
  23.     // Case insensitive file name key for use in a hashtable.
  24.    
  25.     internal class ChameleonKey
  26.     {
  27.         internal string targetNS;
  28.         internal Uri chameleonLocation;
  29.         int hashCode;
  30.        
  31.         public ChameleonKey(string ns, Uri location)
  32.         {
  33.             targetNS = ns;
  34.             chameleonLocation = location;
  35.         }
  36.        
  37.         public override int GetHashCode()
  38.         {
  39.             if (hashCode == 0) {
  40.                 hashCode = targetNS.GetHashCode() + chameleonLocation.GetHashCode();
  41.             }
  42.             return hashCode;
  43.         }
  44.        
  45.         public override bool Equals(object obj)
  46.         {
  47.             if (Ref.ReferenceEquals(this, obj)) {
  48.                 return true;
  49.             }
  50.             ChameleonKey cKey = obj as ChameleonKey;
  51.             if (cKey != null) {
  52.                 return this.targetNS.Equals(cKey.targetNS) && this.chameleonLocation.Equals(cKey.chameleonLocation);
  53.             }
  54.             return false;
  55.         }
  56.     }
  57. }

Developer Fusion