Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XNamespace.cs
Go to the documentation of this file.
3
4namespace System.Xml.Linq;
5
6public sealed class XNamespace
7{
9
11
13
15
16 private readonly string _namespaceName;
17
18 private readonly int _hashCode;
19
20 private readonly XHashtable<XName> _names;
21
22 public string NamespaceName => _namespaceName;
23
24 public static XNamespace None => EnsureNamespace(ref s_refNone, string.Empty);
25
26 public static XNamespace Xml => EnsureNamespace(ref s_refXml, "http://www.w3.org/XML/1998/namespace");
27
28 public static XNamespace Xmlns => EnsureNamespace(ref s_refXmlns, "http://www.w3.org/2000/xmlns/");
29
30 internal XNamespace(string namespaceName)
31 {
33 _hashCode = namespaceName.GetHashCode();
35 }
36
37 public XName GetName(string localName)
38 {
39 if (localName == null)
40 {
41 throw new ArgumentNullException("localName");
42 }
43 return GetName(localName, 0, localName.Length);
44 }
45
46 public override string ToString()
47 {
48 return _namespaceName;
49 }
50
51 public static XNamespace Get(string namespaceName)
52 {
53 if (namespaceName == null)
54 {
55 throw new ArgumentNullException("namespaceName");
56 }
57 return Get(namespaceName, 0, namespaceName.Length);
58 }
59
60 [CLSCompliant(false)]
61 [return: NotNullIfNotNull("namespaceName")]
62 public static implicit operator XNamespace?(string? namespaceName)
63 {
64 if (namespaceName == null)
65 {
66 return null;
67 }
68 return Get(namespaceName);
69 }
70
71 public static XName operator +(XNamespace ns, string localName)
72 {
73 if (ns == null)
74 {
75 throw new ArgumentNullException("ns");
76 }
77 return ns.GetName(localName);
78 }
79
80 public override bool Equals([NotNullWhen(true)] object? obj)
81 {
82 return this == obj;
83 }
84
85 public override int GetHashCode()
86 {
87 return _hashCode;
88 }
89
90 public static bool operator ==(XNamespace? left, XNamespace? right)
91 {
92 return (object)left == right;
93 }
94
95 public static bool operator !=(XNamespace? left, XNamespace? right)
96 {
97 return (object)left != right;
98 }
99
100 internal XName GetName(string localName, int index, int count)
101 {
102 if (_names.TryGetValue(localName, index, count, out var value))
103 {
104 return value;
105 }
106 return _names.Add(new XName(this, localName.Substring(index, count)));
107 }
108
109 internal static XNamespace Get(string namespaceName, int index, int count)
110 {
111 if (count == 0)
112 {
113 return None;
114 }
115 if (s_namespaces == null)
116 {
118 }
120 do
121 {
122 if (!s_namespaces.TryGetValue(namespaceName, index, count, out var value))
123 {
124 if (count == "http://www.w3.org/XML/1998/namespace".Length && string.CompareOrdinal(namespaceName, index, "http://www.w3.org/XML/1998/namespace", 0, count) == 0)
125 {
126 return Xml;
127 }
128 if (count == "http://www.w3.org/2000/xmlns/".Length && string.CompareOrdinal(namespaceName, index, "http://www.w3.org/2000/xmlns/", 0, count) == 0)
129 {
130 return Xmlns;
131 }
133 }
134 xNamespace = ((value != null && value.TryGetTarget(out var target)) ? target : null);
135 }
136 while (xNamespace == null);
137 return xNamespace;
138 }
139
140 private static string ExtractLocalName(XName n)
141 {
142 return n.LocalName;
143 }
144
146 {
147 if (r == null || !r.TryGetTarget(out var target))
148 {
149 return null;
150 }
151 return target.NamespaceName;
152 }
153
155 {
156 XNamespace target;
157 while (true)
158 {
160 if (weakReference != null && weakReference.TryGetTarget(out target))
161 {
162 break;
163 }
165 }
166 return target;
167 }
168}
static int CompareExchange(ref int location1, int value, int comparand)
static XNamespace Xmlns
Definition XNamespace.cs:28
static WeakReference< XNamespace > s_refXmlns
Definition XNamespace.cs:14
static XNamespace EnsureNamespace(ref WeakReference< XNamespace > refNmsp, string namespaceName)
static XName operator+(XNamespace ns, string localName)
Definition XNamespace.cs:71
override string ToString()
Definition XNamespace.cs:46
override int GetHashCode()
Definition XNamespace.cs:85
static bool operator!=(XNamespace? left, XNamespace? right)
Definition XNamespace.cs:95
static string ExtractLocalName(XName n)
static WeakReference< XNamespace > s_refNone
Definition XNamespace.cs:10
static XNamespace Get(string namespaceName, int index, int count)
readonly string _namespaceName
Definition XNamespace.cs:16
static XNamespace Get(string namespaceName)
Definition XNamespace.cs:51
static string ExtractNamespace(WeakReference< XNamespace > r)
static XNamespace None
Definition XNamespace.cs:24
XNamespace(string namespaceName)
Definition XNamespace.cs:30
static XNamespace Xml
Definition XNamespace.cs:26
XName GetName(string localName, int index, int count)
static bool operator==(XNamespace? left, XNamespace? right)
Definition XNamespace.cs:90
XName GetName(string localName)
Definition XNamespace.cs:37
static WeakReference< XNamespace > s_refXml
Definition XNamespace.cs:12
readonly XHashtable< XName > _names
Definition XNamespace.cs:20
override bool Equals([NotNullWhen(true)] object? obj)
Definition XNamespace.cs:80
static XHashtable< WeakReference< XNamespace > > s_namespaces
Definition XNamespace.cs:8