Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XDocument.cs
Go to the documentation of this file.
1using System.IO;
3using System.Text;
6
7namespace System.Xml.Linq;
8
9public class XDocument : XContainer
10{
12
14 {
15 get
16 {
17 return _declaration;
18 }
19 set
20 {
22 }
23 }
24
26
27 public override XmlNodeType NodeType => XmlNodeType.Document;
28
30
31 public XDocument()
32 {
33 }
34
35 public XDocument(params object?[] content)
36 : this()
37 {
39 }
40
46
48 : base(other)
49 {
50 if (other._declaration != null)
51 {
52 _declaration = new XDeclaration(other._declaration);
53 }
54 }
55
56 public static XDocument Load(string uri)
57 {
58 return Load(uri, LoadOptions.None);
59 }
60
61 public static XDocument Load(string uri, LoadOptions options)
62 {
64 using XmlReader reader = XmlReader.Create(uri, xmlReaderSettings);
65 return Load(reader, options);
66 }
67
68 public static XDocument Load(Stream stream)
69 {
70 return Load(stream, LoadOptions.None);
71 }
72
79
87
88 public static XDocument Load(TextReader textReader)
89 {
90 return Load(textReader, LoadOptions.None);
91 }
92
93 public static XDocument Load(TextReader textReader, LoadOptions options)
94 {
96 using XmlReader reader = XmlReader.Create(textReader, xmlReaderSettings);
97 return Load(reader, options);
98 }
99
107
108 public static XDocument Load(XmlReader reader)
109 {
110 return Load(reader, LoadOptions.None);
111 }
112
114 {
115 if (reader == null)
116 {
117 throw new ArgumentNullException("reader");
118 }
119 if (reader.ReadState == ReadState.Initial)
120 {
121 reader.Read();
122 }
124 xDocument.ReadContentFrom(reader, options);
125 if (!reader.EOF)
126 {
128 }
129 if (xDocument.Root == null)
130 {
132 }
133 return xDocument;
134 }
135
137 {
138 if (reader == null)
139 {
140 throw new ArgumentNullException("reader");
141 }
142 if (cancellationToken.IsCancellationRequested)
143 {
145 }
147 }
148
150 {
151 if (reader.ReadState == ReadState.Initial)
152 {
154 }
155 XDocument d = InitLoad(reader, options);
156 await d.ReadContentFromAsync(reader, options, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
157 if (!reader.EOF)
158 {
160 }
161 if (d.Root == null)
162 {
164 }
165 return d;
166 }
167
169 {
171 if ((options & LoadOptions.SetBaseUri) != 0)
172 {
173 string baseURI = reader.BaseURI;
174 if (!string.IsNullOrEmpty(baseURI))
175 {
176 xDocument.SetBaseUri(baseURI);
177 }
178 }
179 if ((options & LoadOptions.SetLineInfo) != 0 && reader is IXmlLineInfo xmlLineInfo && xmlLineInfo.HasLineInfo())
180 {
181 xDocument.SetLineInfo(xmlLineInfo.LineNumber, xmlLineInfo.LinePosition);
182 }
183 if (reader.NodeType == XmlNodeType.XmlDeclaration)
184 {
186 }
187 return xDocument;
188 }
189
190 public static XDocument Parse(string text)
191 {
192 return Parse(text, LoadOptions.None);
193 }
194
202
203 public void Save(Stream stream)
204 {
206 }
207
209 {
211 if (_declaration != null && !string.IsNullOrEmpty(_declaration.Encoding))
212 {
213 try
214 {
216 }
217 catch (ArgumentException)
218 {
219 }
220 }
222 Save(writer);
223 }
224
255
260
267
268 public void Save(XmlWriter writer)
269 {
271 }
272
293
294 public void Save(string fileName)
295 {
297 }
298
303
304 public void Save(string fileName, SaveOptions options)
305 {
307 if (_declaration != null && !string.IsNullOrEmpty(_declaration.Encoding))
308 {
309 try
310 {
312 }
313 catch (ArgumentException)
314 {
315 }
316 }
318 Save(writer);
319 }
320
321 public override void WriteTo(XmlWriter writer)
322 {
323 if (writer == null)
324 {
325 throw new ArgumentNullException("writer");
326 }
327 if (_declaration != null && _declaration.Standalone == "yes")
328 {
329 writer.WriteStartDocument(standalone: true);
330 }
331 else if (_declaration != null && _declaration.Standalone == "no")
332 {
333 writer.WriteStartDocument(standalone: false);
334 }
335 else
336 {
337 writer.WriteStartDocument();
338 }
340 writer.WriteEndDocument();
341 }
342
344 {
345 if (writer == null)
346 {
347 throw new ArgumentNullException("writer");
348 }
349 if (cancellationToken.IsCancellationRequested)
350 {
352 }
354 }
355
357 {
358 Task task = ((_declaration != null && _declaration.Standalone == "yes") ? writer.WriteStartDocumentAsync(standalone: true) : ((_declaration == null || !(_declaration.Standalone == "no")) ? writer.WriteStartDocumentAsync() : writer.WriteStartDocumentAsync(standalone: false)));
361 await writer.WriteEndDocumentAsync().ConfigureAwait(continueOnCapturedContext: false);
362 }
363
364 internal override void AddAttribute(XAttribute a)
365 {
367 }
368
369 internal override void AddAttributeSkipNotify(XAttribute a)
370 {
372 }
373
374 internal override XNode CloneNode()
375 {
376 return new XDocument(this);
377 }
378
379 internal override bool DeepEquals(XNode node)
380 {
381 if (node is XDocument e)
382 {
383 return ContentsEqual(e);
384 }
385 return false;
386 }
387
388 internal override int GetDeepHashCode()
389 {
390 return ContentsHashCode();
391 }
392
394 {
396 if (xNode != null)
397 {
398 do
399 {
400 xNode = xNode.next;
401 if (xNode is T result)
402 {
403 return result;
404 }
405 }
406 while (xNode != content);
407 }
408 return null;
409 }
410
411 internal static bool IsWhitespace(string s)
412 {
413 foreach (char c in s)
414 {
415 if (c != ' ' && c != '\t' && c != '\r' && c != '\n')
416 {
417 return false;
418 }
419 }
420 return true;
421 }
422
423 internal override void ValidateNode(XNode node, XNode previous)
424 {
425 switch (node.NodeType)
426 {
427 case XmlNodeType.Text:
429 break;
430 case XmlNodeType.Element:
432 break;
433 case XmlNodeType.DocumentType:
435 break;
436 case XmlNodeType.CDATA:
438 case XmlNodeType.Document:
440 }
441 }
442
444 {
446 if (xNode == null)
447 {
448 return;
449 }
450 if (previous == null)
451 {
453 }
454 do
455 {
456 xNode = xNode.next;
457 XmlNodeType nodeType = xNode.NodeType;
458 if (nodeType == XmlNodeType.Element || nodeType == XmlNodeType.DocumentType)
459 {
460 if (nodeType != allowBefore)
461 {
463 }
465 }
466 if (xNode == previous)
467 {
469 }
470 }
471 while (xNode != content);
472 }
473
474 internal override void ValidateString(string s)
475 {
476 if (!IsWhitespace(s))
477 {
479 }
480 }
481}
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string InvalidOperation_MissingRoot
Definition SR.cs:56
static string InvalidOperation_DocumentStructure
Definition SR.cs:40
static string Argument_AddAttribute
Definition SR.cs:14
static string Argument_AddNode
Definition SR.cs:16
static string Argument_AddNonWhitespace
Definition SR.cs:18
static string InvalidOperation_ExpectedEndOfFile
Definition SR.cs:44
Definition SR.cs:7
static Encoding GetEncoding(int codepage)
Definition Encoding.cs:593
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)
Definition Task.cs:226
static Task FromCanceled(CancellationToken cancellationToken)
Definition Task.cs:3363
async Task WriteContentToAsync(XmlWriter writer, CancellationToken cancellationToken)
void AddContentSkipNotify(object content)
bool ContentsEqual(XContainer e)
void WriteContentTo(XmlWriter writer)
override void AddAttributeSkipNotify(XAttribute a)
Definition XDocument.cs:369
static Task< XDocument > LoadAsync(XmlReader reader, LoadOptions options, CancellationToken cancellationToken)
Definition XDocument.cs:136
static XDocument Parse(string text)
Definition XDocument.cs:190
void ValidateDocument(XNode previous, XmlNodeType allowBefore, XmlNodeType allowAfter)
Definition XDocument.cs:443
override Task WriteToAsync(XmlWriter writer, CancellationToken cancellationToken)
Definition XDocument.cs:343
static XDocument InitLoad(XmlReader reader, LoadOptions options)
Definition XDocument.cs:168
void Save(string fileName, SaveOptions options)
Definition XDocument.cs:304
override bool DeepEquals(XNode node)
Definition XDocument.cs:379
override XNode CloneNode()
Definition XDocument.cs:374
static XDocument Load(string uri, LoadOptions options)
Definition XDocument.cs:61
XDocument(params object?[] content)
Definition XDocument.cs:35
XDeclaration? Declaration
Definition XDocument.cs:14
static XDocument Load(Stream stream, LoadOptions options)
Definition XDocument.cs:73
static XDocument Load(XmlReader reader)
Definition XDocument.cs:108
XDocumentType? DocumentType
Definition XDocument.cs:25
static XDocument Load(string uri)
Definition XDocument.cs:56
override int GetDeepHashCode()
Definition XDocument.cs:388
void Save(Stream stream)
Definition XDocument.cs:203
static async Task< XDocument > LoadAsync(TextReader textReader, LoadOptions options, CancellationToken cancellationToken)
Definition XDocument.cs:100
void Save(string fileName)
Definition XDocument.cs:294
async Task SaveAsync(Stream stream, SaveOptions options, CancellationToken cancellationToken)
Definition XDocument.cs:225
static XDocument Load(TextReader textReader, LoadOptions options)
Definition XDocument.cs:93
override void ValidateString(string s)
Definition XDocument.cs:474
static XDocument Parse(string text, LoadOptions options)
Definition XDocument.cs:195
Task SaveAsync(XmlWriter writer, CancellationToken cancellationToken)
Definition XDocument.cs:299
override void AddAttribute(XAttribute a)
Definition XDocument.cs:364
override void ValidateNode(XNode node, XNode previous)
Definition XDocument.cs:423
void Save(XmlWriter writer)
Definition XDocument.cs:268
override XmlNodeType NodeType
Definition XDocument.cs:27
void Save(Stream stream, SaveOptions options)
Definition XDocument.cs:208
static bool IsWhitespace(string s)
Definition XDocument.cs:411
override void WriteTo(XmlWriter writer)
Definition XDocument.cs:321
static XDocument Load(TextReader textReader)
Definition XDocument.cs:88
XDeclaration _declaration
Definition XDocument.cs:11
XDocument(XDeclaration? declaration, params object?[] content)
Definition XDocument.cs:41
static async Task< XDocument > LoadAsyncInternal(XmlReader reader, LoadOptions options, CancellationToken cancellationToken)
Definition XDocument.cs:149
async Task SaveAsync(TextWriter textWriter, SaveOptions options, CancellationToken cancellationToken)
Definition XDocument.cs:273
static XDocument Load(Stream stream)
Definition XDocument.cs:68
static XDocument Load(XmlReader reader, LoadOptions options)
Definition XDocument.cs:113
XDocument(XDocument other)
Definition XDocument.cs:47
void Save(TextWriter textWriter)
Definition XDocument.cs:256
void Save(TextWriter textWriter, SaveOptions options)
Definition XDocument.cs:261
async Task WriteToAsyncInternal(XmlWriter writer, CancellationToken cancellationToken)
Definition XDocument.cs:356
static async Task< XDocument > LoadAsync(Stream stream, LoadOptions options, CancellationToken cancellationToken)
Definition XDocument.cs:80
static XmlWriterSettings GetXmlWriterSettings(SaveOptions o)
Definition XNode.cs:512
static XmlReaderSettings GetXmlReaderSettings(LoadOptions o)
Definition XNode.cs:500
SaveOptions GetSaveOptionsFromAnnotations()
Definition XObject.cs:490
virtual Task< bool > ReadAsync()
XmlNodeType NodeType
Definition XmlReader.cs:62
static XmlReader Create(string inputUri)
static XmlWriter Create(string outputFileName)
Definition XmlWriter.cs:468
ValueTask DisposeAsync()