Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlWriterSettings.cs
Go to the documentation of this file.
3using System.IO;
4using System.Text;
6
7namespace System.Xml;
8
9public sealed class XmlWriterSettings
10{
12 {
13 ReadOnly = true
14 };
15
16 private bool _useAsync;
17
19
20 private bool _omitXmlDecl;
21
23
24 private string _newLineChars;
25
27
28 private string _indentChars;
29
31
32 private bool _closeOutput;
33
35
37
38 private bool _checkCharacters;
39
41
43
45
47
48 private bool _mergeCDataSections;
49
50 private string _mediaType;
51
52 private string _docTypeSystem;
53
54 private string _docTypePublic;
55
57
58 private bool _autoXmlDecl;
59
60 private bool _isReadOnly;
61
62 public bool Async
63 {
64 get
65 {
66 return _useAsync;
67 }
68 set
69 {
70 CheckReadOnly("Async");
72 }
73 }
74
76 {
77 get
78 {
79 return _encoding;
80 }
81 [MemberNotNull("_encoding")]
82 set
83 {
84 CheckReadOnly("Encoding");
86 }
87 }
88
90 {
91 get
92 {
93 return _omitXmlDecl;
94 }
95 set
96 {
97 CheckReadOnly("OmitXmlDeclaration");
99 }
100 }
101
103 {
104 get
105 {
106 return _newLineHandling;
107 }
108 set
109 {
110 CheckReadOnly("NewLineHandling");
111 if ((uint)value > 2u)
112 {
113 throw new ArgumentOutOfRangeException("value");
114 }
116 }
117 }
118
119 public string NewLineChars
120 {
121 get
122 {
123 return _newLineChars;
124 }
125 [MemberNotNull("_newLineChars")]
126 set
127 {
128 CheckReadOnly("NewLineChars");
129 if (value == null)
130 {
131 throw new ArgumentNullException("value");
132 }
134 }
135 }
136
137 public bool Indent
138 {
139 get
140 {
141 return _indent == TriState.True;
142 }
143 set
144 {
145 CheckReadOnly("Indent");
146 _indent = (value ? TriState.True : TriState.False);
147 }
148 }
149
150 public string IndentChars
151 {
152 get
153 {
154 return _indentChars;
155 }
156 [MemberNotNull("_indentChars")]
157 set
158 {
159 CheckReadOnly("IndentChars");
160 if (value == null)
161 {
162 throw new ArgumentNullException("value");
163 }
165 }
166 }
167
169 {
170 get
171 {
173 }
174 set
175 {
176 CheckReadOnly("NewLineOnAttributes");
178 }
179 }
180
181 public bool CloseOutput
182 {
183 get
184 {
185 return _closeOutput;
186 }
187 set
188 {
189 CheckReadOnly("CloseOutput");
191 }
192 }
193
195 {
196 get
197 {
198 return _conformanceLevel;
199 }
200 set
201 {
202 CheckReadOnly("ConformanceLevel");
203 if ((uint)value > 2u)
204 {
205 throw new ArgumentOutOfRangeException("value");
206 }
208 }
209 }
210
211 public bool CheckCharacters
212 {
213 get
214 {
215 return _checkCharacters;
216 }
217 set
218 {
219 CheckReadOnly("CheckCharacters");
221 }
222 }
223
225 {
226 get
227 {
228 return _namespaceHandling;
229 }
230 set
231 {
232 CheckReadOnly("NamespaceHandling");
233 if ((uint)value > 1u)
234 {
235 throw new ArgumentOutOfRangeException("value");
236 }
238 }
239 }
240
242 {
243 get
244 {
246 }
247 set
248 {
249 CheckReadOnly("WriteEndDocumentOnClose");
251 }
252 }
253
254 public XmlOutputMethod OutputMethod
255 {
256 get
257 {
258 return _outputMethod;
259 }
260 internal set
261 {
263 }
264 }
265
267
269 {
270 get
271 {
273 }
274 set
275 {
276 CheckReadOnly("DoNotEscapeUriAttributes");
278 }
279 }
280
281 internal bool MergeCDataSections
282 {
283 get
284 {
285 return _mergeCDataSections;
286 }
287 set
288 {
289 CheckReadOnly("MergeCDataSections");
291 }
292 }
293
294 internal string? MediaType
295 {
296 get
297 {
298 return _mediaType;
299 }
300 set
301 {
302 CheckReadOnly("MediaType");
304 }
305 }
306
307 internal string? DocTypeSystem
308 {
309 get
310 {
311 return _docTypeSystem;
312 }
313 set
314 {
315 CheckReadOnly("DocTypeSystem");
317 }
318 }
319
320 internal string? DocTypePublic
321 {
322 get
323 {
324 return _docTypePublic;
325 }
326 set
327 {
328 CheckReadOnly("DocTypePublic");
330 }
331 }
332
334 {
335 get
336 {
337 return _standalone;
338 }
339 set
340 {
341 CheckReadOnly("Standalone");
343 }
344 }
345
346 internal bool AutoXmlDeclaration
347 {
348 get
349 {
350 return _autoXmlDecl;
351 }
352 set
353 {
354 CheckReadOnly("AutoXmlDeclaration");
356 }
357 }
358
360 {
361 get
362 {
363 return _indent;
364 }
365 set
366 {
367 _indent = value;
368 }
369 }
370
371 internal bool IsQuerySpecific
372 {
373 get
374 {
375 if (_cdataSections.Count == 0 && _docTypePublic == null && _docTypeSystem == null)
376 {
377 return _standalone == XmlStandalone.Yes;
378 }
379 return true;
380 }
381 }
382
383 internal bool ReadOnly
384 {
385 get
386 {
387 return _isReadOnly;
388 }
389 set
390 {
392 }
393 }
394
396 {
397 Initialize();
398 }
399
400 public void Reset()
401 {
402 CheckReadOnly("Reset");
403 Initialize();
404 }
405
413
415 {
416 if (outputFileName == null)
417 {
418 throw new ArgumentNullException("outputFileName");
419 }
421 if (!xmlWriterSettings.CloseOutput)
422 {
425 }
426 FileStream fileStream = null;
427 try
428 {
429 fileStream = new FileStream(outputFileName, FileMode.Create, FileAccess.Write, FileShare.Read, 4096, _useAsync);
430 return xmlWriterSettings.CreateWriter(fileStream);
431 }
432 catch
433 {
434 fileStream?.Dispose();
435 throw;
436 }
437 }
438
440 {
441 if (output == null)
442 {
443 throw new ArgumentNullException("output");
444 }
446 if (Encoding.WebName == "utf-8")
447 {
448 switch (OutputMethod)
449 {
450 case XmlOutputMethod.Xml:
452 break;
453 case XmlOutputMethod.Html:
455 break;
456 case XmlOutputMethod.Text:
458 break;
459 case XmlOutputMethod.AutoDetect:
461 break;
462 default:
463 return null;
464 }
465 }
466 else
467 {
468 switch (OutputMethod)
469 {
470 case XmlOutputMethod.Xml:
472 break;
473 case XmlOutputMethod.Html:
475 break;
476 case XmlOutputMethod.Text:
478 break;
479 case XmlOutputMethod.AutoDetect:
481 break;
482 default:
483 return null;
484 }
485 }
486 if (OutputMethod != XmlOutputMethod.AutoDetect && IsQuerySpecific)
487 {
489 }
491 if (_useAsync)
492 {
494 }
495 return xmlWriter;
496 }
497
499 {
500 if (output == null)
501 {
502 throw new ArgumentNullException("output");
503 }
505 switch (OutputMethod)
506 {
507 case XmlOutputMethod.Xml:
509 break;
510 case XmlOutputMethod.Html:
512 break;
513 case XmlOutputMethod.Text:
515 break;
516 case XmlOutputMethod.AutoDetect:
518 break;
519 default:
520 return null;
521 }
522 if (OutputMethod != XmlOutputMethod.AutoDetect && IsQuerySpecific)
523 {
525 }
527 if (_useAsync)
528 {
530 }
531 return xmlWriter;
532 }
533
535 {
536 if (output == null)
537 {
538 throw new ArgumentNullException("output");
539 }
541 }
542
543 private void CheckReadOnly(string propertyName)
544 {
545 if (_isReadOnly)
546 {
547 throw new XmlException(System.SR.Xml_ReadOnlyProperty, GetType().Name + "." + propertyName);
548 }
549 }
550
551 [MemberNotNull("_encoding")]
552 [MemberNotNull("_newLineChars")]
553 [MemberNotNull("_indentChars")]
554 private void Initialize()
555 {
557 _omitXmlDecl = false;
560 _indent = TriState.Unknown;
561 _indentChars = " ";
562 _newLineOnAttributes = false;
563 _closeOutput = false;
566 _checkCharacters = true;
570 _mergeCDataSections = false;
571 _mediaType = null;
572 _docTypeSystem = null;
573 _docTypePublic = null;
576 _useAsync = false;
577 _isReadOnly = false;
578 }
579
581 {
583 XmlWriterSettings settings = baseWriter.Settings;
584 bool flag = false;
585 bool checkNames = false;
586 bool flag2 = false;
587 bool flag3 = false;
588 if (settings == null)
589 {
590 if (_newLineHandling == NewLineHandling.Replace)
591 {
592 flag2 = true;
593 flag3 = true;
594 }
596 {
597 flag = true;
598 flag3 = true;
599 }
600 }
601 else
602 {
603 if (_conformanceLevel != settings.ConformanceLevel)
604 {
606 flag3 = true;
607 }
608 if (_checkCharacters && !settings.CheckCharacters)
609 {
610 flag = true;
612 flag3 = true;
613 }
614 if (_newLineHandling == NewLineHandling.Replace && settings.NewLineHandling == NewLineHandling.None)
615 {
616 flag2 = true;
617 flag3 = true;
618 }
619 }
621 if (flag3)
622 {
623 if (conformanceLevel != 0)
624 {
626 }
627 if (flag || flag2)
628 {
630 }
631 }
632 if (IsQuerySpecific && (settings == null || !settings.IsQuerySpecific))
633 {
635 }
636 return xmlWriter;
637 }
638
640 {
641 writer.Write(Encoding.CodePage);
643 writer.Write((sbyte)NewLineHandling);
644 writer.WriteStringQ(NewLineChars);
645 writer.Write((sbyte)IndentInternal);
646 writer.WriteStringQ(IndentChars);
648 writer.Write(CloseOutput);
649 writer.Write((sbyte)ConformanceLevel);
650 writer.Write(CheckCharacters);
651 writer.Write((sbyte)_outputMethod);
654 {
655 writer.Write(cdataSection.Name);
656 writer.Write(cdataSection.Namespace);
657 }
659 writer.WriteStringQ(_mediaType);
660 writer.WriteStringQ(_docTypeSystem);
661 writer.WriteStringQ(_docTypePublic);
662 writer.Write((sbyte)_standalone);
663 writer.Write(_autoXmlDecl);
664 writer.Write(ReadOnly);
665 }
666
668 {
672 NewLineChars = reader.ReadStringQ();
673 IndentInternal = (TriState)reader.ReadSByte(-1, 1);
674 IndentChars = reader.ReadStringQ();
676 CloseOutput = reader.ReadBoolean();
678 CheckCharacters = reader.ReadBoolean();
680 int num = reader.ReadInt32();
682 for (int i = 0; i < num; i++)
683 {
685 }
687 _mediaType = reader.ReadStringQ();
688 _docTypeSystem = reader.ReadStringQ();
689 _docTypePublic = reader.ReadStringQ();
690 Standalone = (XmlStandalone)reader.ReadSByte(0, 2);
691 _autoXmlDecl = reader.ReadBoolean();
692 ReadOnly = reader.ReadBoolean();
693 }
694}
void Add(TKey key, TValue value)
static string NewLine
virtual bool ReadBoolean()
virtual string ReadString()
virtual int ReadInt32()
static string Xml_ReadOnlyProperty
Definition SR.cs:156
Definition SR.cs:7
static Encoding UTF8
Definition Encoding.cs:526
static Encoding GetEncoding(int codepage)
Definition Encoding.cs:593
virtual string WebName
Definition Encoding.cs:386
virtual int CodePage
Definition Encoding.cs:515
XmlWriter AddConformanceWrapper(XmlWriter baseWriter)
List< XmlQualifiedName > _cdataSections
XmlWriter CreateWriter(TextWriter output)
void GetObjectData(XmlQueryDataWriter writer)
static readonly XmlWriterSettings s_defaultWriterSettings
XmlWriter CreateWriter(XmlWriter output)
void CheckReadOnly(string propertyName)
XmlWriter CreateWriter(Stream output)
XmlWriter CreateWriter(string outputFileName)
NamespaceHandling _namespaceHandling
XmlWriterSettings(XmlQueryDataReader reader)
List< XmlQualifiedName > CDataSectionElements
sbyte ReadSByte(sbyte minValue, sbyte maxValue)