The Labs \ Source Viewer \ SSCLI \ System.Xml.Xsl.Qil \ QilName

  1. //------------------------------------------------------------------------------
  2. // <copyright file="QilName.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. //------------------------------------------------------------------------------
  15. using System;
  16. using System.Diagnostics;
  17. namespace System.Xml.Xsl.Qil
  18. {
  19.    
  20.     /// <summary>
  21.     /// View over a Qil name literal.
  22.     /// </summary>
  23.     /// <remarks>
  24.     /// Don't construct QIL nodes directly; instead, use the <see cref="QilFactory">QilFactory</see>.
  25.     /// </remarks>
  26.     internal class QilName : QilLiteral
  27.     {
  28.         private string local;
  29.         private string uri;
  30.         private string prefix;
  31.        
  32.        
  33.         //-----------------------------------------------
  34.         // Constructor
  35.         //-----------------------------------------------
  36.        
  37.         /// <summary>
  38.         /// Construct a new node
  39.         /// </summary>
  40.         public QilName(QilNodeType nodeType, string local, string uri, string prefix) : base(nodeType, null)
  41.         {
  42.             LocalName = local;
  43.             NamespaceUri = uri;
  44.             Prefix = prefix;
  45.             Value = this;
  46.         }
  47.        
  48.        
  49.         //-----------------------------------------------
  50.         // QilName methods
  51.         //-----------------------------------------------
  52.        
  53.         public string LocalName {
  54.             get { return this.local; }
  55.             set { this.local = value; }
  56.         }
  57.        
  58.         public string NamespaceUri {
  59.             get { return this.uri; }
  60.             set { this.uri = value; }
  61.         }
  62.        
  63.         public string Prefix {
  64.             get { return this.prefix; }
  65.             set { this.prefix = value; }
  66.         }
  67.        
  68.         /// <summary>
  69.         /// Build the qualified name in the form prefix:local
  70.         /// </summary>
  71.         public string QualifiedName {
  72.             get {
  73.                 if (this.prefix.Length == 0) {
  74.                     return this.local;
  75.                 }
  76.                 else {
  77.                     return this.prefix + ':' + this.local;
  78.                 }
  79.             }
  80.         }
  81.        
  82.         /// <summary>
  83.         /// Override GetHashCode() so that the QilName can be used as a key in the hashtable.
  84.         /// </summary>
  85.         /// <remarks>Does not compare their prefixes (if any).</remarks>
  86.         public override int GetHashCode()
  87.         {
  88.             return this.local.GetHashCode();
  89.         }
  90.        
  91.         /// <summary>
  92.         /// Override Equals() so that the QilName can be used as a key in the hashtable.
  93.         /// </summary>
  94.         /// <remarks>Does not compare their prefixes (if any).</remarks>
  95.         public override bool Equals(object other)
  96.         {
  97.             QilName name = other as QilName;
  98.             if (name == null)
  99.                 return false;
  100.            
  101.             return this.local == name.local && this.uri == name.uri;
  102.         }
  103.        
  104.         /// <summary>
  105.         /// Return the QilName in this format: "{namespace}prefix:local-name".
  106.         /// If the namespace is empty, return the QilName in this truncated format: "local-name".
  107.         /// If the prefix is empty, return the QilName in this truncated format: "{namespace}local-name".
  108.         /// </summary>
  109.         public override string ToString()
  110.         {
  111.             if (prefix.Length == 0) {
  112.                 if (uri.Length == 0)
  113.                     return local;
  114.                
  115.                 return string.Concat("{", uri, "}", local);
  116.             }
  117.            
  118.             return string.Concat("{", uri, "}", prefix, ":", local);
  119.         }
  120.     }
  121. }

Developer Fusion