2 // System.Xml.XmlQualifiedName.cs
4 // Author: Duncan Mak (duncan@ximian.com)
9 // 21st June 2002 : Ajay kumar Dwivedi (adwiv@yahoo.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 public class XmlQualifiedName
42 public XmlQualifiedName ()
43 : this (string.Empty, string.Empty)
47 public XmlQualifiedName (string name)
48 : this (name, string.Empty)
52 public XmlQualifiedName (string name, string ns)
55 this.name = (name == null) ? "" : name;
56 this.ns = (ns == null) ? "" : ns;
57 this.hash = this.name.GetHashCode () ^ this.ns.GetHashCode ();
61 public static readonly XmlQualifiedName Empty = new XmlQualifiedName ();
62 private readonly string name;
63 private readonly string ns;
64 private readonly int hash;
70 return name.Length == 0 && ns.Length == 0;
79 public string Namespace
85 public override bool Equals (object other)
87 return this == (other as XmlQualifiedName);
90 public override int GetHashCode ()
95 public override string ToString ()
97 if (ns == string.Empty)
100 return ns + ":" + name;
103 public static string ToString (string name, string ns)
105 if (ns == string.Empty)
108 return ns + ":" + name;
111 internal static XmlQualifiedName Parse (string name, IXmlNamespaceResolver resolver)
113 int index = name.IndexOf (':');
115 return new XmlQualifiedName (name);
116 string ns = resolver.LookupNamespace (name.Substring (0, index));
118 throw new ArgumentException ("Invalid qualified name.");
119 return new XmlQualifiedName (name.Substring (index + 1), ns);
122 internal static XmlQualifiedName Parse (string name, XmlReader reader)
124 int index = name.IndexOf (':');
126 return new XmlQualifiedName (name);
127 string ns = reader.LookupNamespace (name.Substring (0, index));
129 throw new ArgumentException ("Invalid qualified name.");
130 return new XmlQualifiedName (name.Substring (index + 1), ns);
134 public static bool operator == (XmlQualifiedName a, XmlQualifiedName b)
136 if((Object)a == (Object)b)
139 if((Object)a == null || (Object)b == null)
142 return (a.hash == b.hash) && (a.name == b.name) && (a.ns == b.ns);
145 public static bool operator != (XmlQualifiedName a, XmlQualifiedName b)