5 // Copyright 2007 Novell (http://www.novell.com)
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 using System.Collections;
29 using System.Collections.Generic;
34 namespace System.Xml.Linq
36 public sealed class XNamespace
38 static readonly XNamespace blank, xml, xmlns;
39 static Dictionary<string, XNamespace> nstable;
43 nstable = new Dictionary<string, XNamespace> ();
44 blank = Get (String.Empty);
45 xml = Get ("http://www.w3.org/XML/1998/namespace");
46 xmlns = Get ("http://www.w3.org/2000/xmlns/");
49 public static XNamespace None {
53 public static XNamespace Xml {
57 public static XNamespace Xmlns {
61 public static XNamespace Get (string uri)
65 if (!nstable.TryGetValue (uri, out ret)) {
66 ret = new XNamespace (uri);
73 public XName GetName (string localName)
76 table = new Dictionary<string, XName> ();
79 if (!table.TryGetValue (localName, out ret)) {
80 ret = new XName (localName, this);
81 table [localName] = ret;
88 Dictionary<string, XName> table;
90 XNamespace (string namespaceName)
92 if (namespaceName == null)
93 throw new ArgumentNullException ("namespaceName");
97 public string NamespaceName {
101 public override bool Equals (object other)
103 if (Object.ReferenceEquals (this, other))
105 XNamespace ns = other as XNamespace;
106 return ns != null && uri == ns.uri;
109 public static bool operator == (XNamespace o1, XNamespace o2)
111 return (object) o1 != null ? o1.Equals (o2) : (object) o2 == null;
114 public static bool operator != (XNamespace o1, XNamespace o2)
119 public static XName operator + (XNamespace ns, string localName)
121 return new XName (localName, ns);
124 [CLSCompliant (false)]
125 public static implicit operator XNamespace (string s)
127 return s != null ? XNamespace.Get (s) : null;
130 public override int GetHashCode ()
132 return uri.GetHashCode ();
135 public override string ToString ()