Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XAttribute.cs
Go to the documentation of this file.
5using System.IO;
6
7namespace System.Xml.Linq;
8
9[TypeDescriptionProvider("MS.Internal.Xml.Linq.ComponentModel.XTypeDescriptionProvider`1[[System.Xml.Linq.XAttribute, System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]],System.ComponentModel.TypeConverter")]
10public class XAttribute : XObject
11{
12 internal XAttribute next;
13
14 internal XName name;
15
16 internal string value;
17
19
21 {
22 get
23 {
25 if (namespaceName.Length == 0)
26 {
27 return name.LocalName == "xmlns";
28 }
29 return (object)namespaceName == "http://www.w3.org/2000/xmlns/";
30 }
31 }
32
33 public XName Name => name;
34
36 {
37 get
38 {
39 if (parent == null || ((XElement)parent).lastAttr == this)
40 {
41 return null;
42 }
43 return next;
44 }
45 }
46
47 public override XmlNodeType NodeType => XmlNodeType.Attribute;
48
50 {
51 get
52 {
53 if (parent == null)
54 {
55 return null;
56 }
57 XAttribute lastAttr = ((XElement)parent).lastAttr;
58 while (lastAttr.next != this)
59 {
60 lastAttr = lastAttr.next;
61 }
62 if (lastAttr == ((XElement)parent).lastAttr)
63 {
64 return null;
65 }
66 return lastAttr;
67 }
68 }
69
70 public string Value
71 {
72 get
73 {
74 return value;
75 }
76 set
77 {
78 if (value == null)
79 {
80 throw new ArgumentNullException("value");
81 }
85 if (flag)
86 {
88 }
89 }
90 }
91
92 public XAttribute(XName name, object value)
93 {
94 if (name == null)
95 {
96 throw new ArgumentNullException("name");
97 }
98 if (value == null)
99 {
100 throw new ArgumentNullException("value");
101 }
104 this.name = name;
106 }
107
109 {
110 if (other == null)
111 {
112 throw new ArgumentNullException("other");
113 }
114 name = other.name;
115 value = other.value;
116 }
117
118 public void Remove()
119 {
120 if (parent == null)
121 {
123 }
124 ((XElement)parent).RemoveAttribute(this);
125 }
126
127 public void SetValue(object value)
128 {
129 if (value == null)
130 {
131 throw new ArgumentNullException("value");
132 }
134 }
135
147
148 [CLSCompliant(false)]
149 [return: NotNullIfNotNull("attribute")]
150 public static explicit operator string?(XAttribute? attribute)
151 {
152 return attribute?.value;
153 }
154
155 [CLSCompliant(false)]
156 public static explicit operator bool(XAttribute attribute)
157 {
158 if (attribute == null)
159 {
160 throw new ArgumentNullException("attribute");
161 }
162 return XmlConvert.ToBoolean(attribute.value.ToLowerInvariant());
163 }
164
165 [CLSCompliant(false)]
166 [return: NotNullIfNotNull("attribute")]
167 public static explicit operator bool?(XAttribute? attribute)
168 {
169 if (attribute == null)
170 {
171 return null;
172 }
173 return XmlConvert.ToBoolean(attribute.value.ToLowerInvariant());
174 }
175
176 [CLSCompliant(false)]
177 public static explicit operator int(XAttribute attribute)
178 {
179 if (attribute == null)
180 {
181 throw new ArgumentNullException("attribute");
182 }
183 return XmlConvert.ToInt32(attribute.value);
184 }
185
186 [CLSCompliant(false)]
187 [return: NotNullIfNotNull("attribute")]
188 public static explicit operator int?(XAttribute? attribute)
189 {
190 if (attribute == null)
191 {
192 return null;
193 }
194 return XmlConvert.ToInt32(attribute.value);
195 }
196
197 [CLSCompliant(false)]
198 public static explicit operator uint(XAttribute attribute)
199 {
200 if (attribute == null)
201 {
202 throw new ArgumentNullException("attribute");
203 }
204 return XmlConvert.ToUInt32(attribute.value);
205 }
206
207 [CLSCompliant(false)]
208 [return: NotNullIfNotNull("attribute")]
209 public static explicit operator uint?(XAttribute? attribute)
210 {
211 if (attribute == null)
212 {
213 return null;
214 }
215 return XmlConvert.ToUInt32(attribute.value);
216 }
217
218 [CLSCompliant(false)]
219 public static explicit operator long(XAttribute attribute)
220 {
221 if (attribute == null)
222 {
223 throw new ArgumentNullException("attribute");
224 }
225 return XmlConvert.ToInt64(attribute.value);
226 }
227
228 [CLSCompliant(false)]
229 [return: NotNullIfNotNull("attribute")]
230 public static explicit operator long?(XAttribute? attribute)
231 {
232 if (attribute == null)
233 {
234 return null;
235 }
236 return XmlConvert.ToInt64(attribute.value);
237 }
238
239 [CLSCompliant(false)]
240 public static explicit operator ulong(XAttribute attribute)
241 {
242 if (attribute == null)
243 {
244 throw new ArgumentNullException("attribute");
245 }
246 return XmlConvert.ToUInt64(attribute.value);
247 }
248
249 [CLSCompliant(false)]
250 [return: NotNullIfNotNull("attribute")]
251 public static explicit operator ulong?(XAttribute? attribute)
252 {
253 if (attribute == null)
254 {
255 return null;
256 }
257 return XmlConvert.ToUInt64(attribute.value);
258 }
259
260 [CLSCompliant(false)]
261 public static explicit operator float(XAttribute attribute)
262 {
263 if (attribute == null)
264 {
265 throw new ArgumentNullException("attribute");
266 }
267 return XmlConvert.ToSingle(attribute.value);
268 }
269
270 [CLSCompliant(false)]
271 [return: NotNullIfNotNull("attribute")]
272 public static explicit operator float?(XAttribute? attribute)
273 {
274 if (attribute == null)
275 {
276 return null;
277 }
278 return XmlConvert.ToSingle(attribute.value);
279 }
280
281 [CLSCompliant(false)]
282 public static explicit operator double(XAttribute attribute)
283 {
284 if (attribute == null)
285 {
286 throw new ArgumentNullException("attribute");
287 }
288 return XmlConvert.ToDouble(attribute.value);
289 }
290
291 [CLSCompliant(false)]
292 [return: NotNullIfNotNull("attribute")]
293 public static explicit operator double?(XAttribute? attribute)
294 {
295 if (attribute == null)
296 {
297 return null;
298 }
299 return XmlConvert.ToDouble(attribute.value);
300 }
301
302 [CLSCompliant(false)]
303 public static explicit operator decimal(XAttribute attribute)
304 {
305 if (attribute == null)
306 {
307 throw new ArgumentNullException("attribute");
308 }
309 return XmlConvert.ToDecimal(attribute.value);
310 }
311
312 [CLSCompliant(false)]
313 [return: NotNullIfNotNull("attribute")]
314 public static explicit operator decimal?(XAttribute? attribute)
315 {
316 if (attribute == null)
317 {
318 return null;
319 }
320 return XmlConvert.ToDecimal(attribute.value);
321 }
322
323 [CLSCompliant(false)]
324 public static explicit operator DateTime(XAttribute attribute)
325 {
326 if (attribute == null)
327 {
328 throw new ArgumentNullException("attribute");
329 }
331 }
332
333 [CLSCompliant(false)]
334 [return: NotNullIfNotNull("attribute")]
335 public static explicit operator DateTime?(XAttribute? attribute)
336 {
337 if (attribute == null)
338 {
339 return null;
340 }
342 }
343
344 [CLSCompliant(false)]
345 public static explicit operator DateTimeOffset(XAttribute attribute)
346 {
347 if (attribute == null)
348 {
349 throw new ArgumentNullException("attribute");
350 }
352 }
353
354 [CLSCompliant(false)]
355 [return: NotNullIfNotNull("attribute")]
356 public static explicit operator DateTimeOffset?(XAttribute? attribute)
357 {
358 if (attribute == null)
359 {
360 return null;
361 }
363 }
364
365 [CLSCompliant(false)]
366 public static explicit operator TimeSpan(XAttribute attribute)
367 {
368 if (attribute == null)
369 {
370 throw new ArgumentNullException("attribute");
371 }
372 return XmlConvert.ToTimeSpan(attribute.value);
373 }
374
375 [CLSCompliant(false)]
376 [return: NotNullIfNotNull("attribute")]
377 public static explicit operator TimeSpan?(XAttribute? attribute)
378 {
379 if (attribute == null)
380 {
381 return null;
382 }
383 return XmlConvert.ToTimeSpan(attribute.value);
384 }
385
386 [CLSCompliant(false)]
387 public static explicit operator Guid(XAttribute attribute)
388 {
389 if (attribute == null)
390 {
391 throw new ArgumentNullException("attribute");
392 }
393 return XmlConvert.ToGuid(attribute.value);
394 }
395
396 [CLSCompliant(false)]
397 [return: NotNullIfNotNull("attribute")]
398 public static explicit operator Guid?(XAttribute? attribute)
399 {
400 if (attribute == null)
401 {
402 return null;
403 }
404 return XmlConvert.ToGuid(attribute.value);
405 }
406
407 internal int GetDeepHashCode()
408 {
409 return name.GetHashCode() ^ value.GetHashCode();
410 }
411
413 {
414 string namespaceName = ns.NamespaceName;
415 if (namespaceName.Length == 0)
416 {
417 return string.Empty;
418 }
419 if (parent != null)
420 {
421 return ((XElement)parent).GetPrefixOfNamespace(ns);
422 }
423 if ((object)namespaceName == "http://www.w3.org/XML/1998/namespace")
424 {
425 return "xml";
426 }
427 if ((object)namespaceName == "http://www.w3.org/2000/xmlns/")
428 {
429 return "xmlns";
430 }
431 return null;
432 }
433
434 private static void ValidateAttribute(XName name, string value)
435 {
437 if ((object)namespaceName == "http://www.w3.org/2000/xmlns/")
438 {
439 if (value.Length == 0)
440 {
442 }
443 if (value == "http://www.w3.org/XML/1998/namespace")
444 {
445 if (name.LocalName != "xml")
446 {
448 }
449 return;
450 }
451 if (value == "http://www.w3.org/2000/xmlns/")
452 {
454 }
455 string localName = name.LocalName;
456 if (localName == "xml")
457 {
459 }
460 if (localName == "xmlns")
461 {
463 }
464 }
465 else if (namespaceName.Length == 0 && name.LocalName == "xmlns")
466 {
467 if (value == "http://www.w3.org/XML/1998/namespace")
468 {
470 }
471 if (value == "http://www.w3.org/2000/xmlns/")
472 {
474 }
475 }
476 }
477}
static CultureInfo InvariantCulture
static string InvalidOperation_MissingParent
Definition SR.cs:54
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string Argument_NamespaceDeclarationPrefixed
Definition SR.cs:30
static string Argument_NamespaceDeclarationXml
Definition SR.cs:32
static string Argument_NamespaceDeclarationXmlns
Definition SR.cs:34
Definition SR.cs:7
XAttribute(XAttribute other)
XAttribute? PreviousAttribute
Definition XAttribute.cs:50
void SetValue(object value)
XAttribute(XName name, object value)
Definition XAttribute.cs:92
override XmlNodeType NodeType
Definition XAttribute.cs:47
string GetPrefixOfNamespace(XNamespace ns)
static IEnumerable< XAttribute > EmptySequence
Definition XAttribute.cs:18
override string ToString()
static void ValidateAttribute(XName name, string value)
static string GetStringValue(object value)
string NamespaceName
Definition XName.cs:18
XNamespace Namespace
Definition XName.cs:16
override int GetHashCode()
Definition XName.cs:79
static readonly XObjectChangeEventArgs Value
XContainer parent
Definition XObject.cs:7
bool NotifyChanging(object sender, XObjectChangeEventArgs e)
Definition XObject.cs:428
bool NotifyChanged(object sender, XObjectChangeEventArgs e)
Definition XObject.cs:399
static bool ToBoolean(string s)
static DateTimeOffset ToDateTimeOffset(string s)
static uint ToUInt32(string s)
static int ToInt32(string s)
static float ToSingle(string s)
static TimeSpan ToTimeSpan(string s)
static double ToDouble(string s)
static Guid ToGuid(string s)
static decimal ToDecimal(string s)
static ulong ToUInt64(string s)
static long ToInt64(string s)
static XmlWriter Create(string outputFileName)
Definition XmlWriter.cs:468
static DateTime Parse(string s)
Definition DateTime.cs:919