Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XNodeBuilder.cs
Go to the documentation of this file.
2
3namespace System.Xml.Linq;
4
5internal sealed class XNodeBuilder : XmlWriter
6{
8
10
12
13 private string _attrValue;
14
15 private readonly XContainer _root;
16
26
27 public override WriteState WriteState
28 {
29 get
30 {
31 throw new NotSupportedException();
32 }
33 }
34
35 public XNodeBuilder(XContainer container)
36 {
37 _root = container;
38 }
39
40 protected override void Dispose(bool disposing)
41 {
42 if (disposing)
43 {
44 Close();
45 }
46 }
47
48 public override void Close()
49 {
51 }
52
53 public override void Flush()
54 {
55 }
56
57 public override string LookupPrefix(string namespaceName)
58 {
59 throw new NotSupportedException();
60 }
61
62 public override void WriteBase64(byte[] buffer, int index, int count)
63 {
65 }
66
67 public override void WriteCData(string text)
68 {
69 AddNode(new XCData(text));
70 }
71
72 public override void WriteCharEntity(char ch)
73 {
74 AddString(char.ToString(ch));
75 }
76
77 public override void WriteChars(char[] buffer, int index, int count)
78 {
79 AddString(new string(buffer, index, count));
80 }
81
82 public override void WriteComment(string text)
83 {
84 AddNode(new XComment(text));
85 }
86
87 public override void WriteDocType(string name, string pubid, string sysid, string subset)
88 {
90 }
91
92 public override void WriteEndAttribute()
93 {
95 _attrName = null;
96 _attrValue = null;
97 if (_parent != null)
98 {
100 }
101 else
102 {
104 }
105 }
106
107 public override void WriteEndDocument()
108 {
109 }
110
111 public override void WriteEndElement()
112 {
114 }
115
116 public override void WriteEntityRef(string name)
117 {
118 switch (name)
119 {
120 case "amp":
121 AddString("&");
122 break;
123 case "apos":
124 AddString("'");
125 break;
126 case "gt":
127 AddString(">");
128 break;
129 case "lt":
130 AddString("<");
131 break;
132 case "quot":
133 AddString("\"");
134 break;
135 default:
137 }
138 }
139
140 public override void WriteFullEndElement()
141 {
143 if (xElement.IsEmpty)
144 {
145 xElement.Add(string.Empty);
146 }
147 _parent = xElement.parent;
148 }
149
150 public override void WriteProcessingInstruction(string name, string text)
151 {
152 if (!(name == "xml"))
153 {
155 }
156 }
157
158 public override void WriteRaw(char[] buffer, int index, int count)
159 {
160 AddString(new string(buffer, index, count));
161 }
162
163 public override void WriteRaw(string data)
164 {
165 AddString(data);
166 }
167
168 public override void WriteStartAttribute(string prefix, string localName, string namespaceName)
169 {
170 if (prefix == null)
171 {
172 throw new ArgumentNullException("prefix");
173 }
174 _attrName = XNamespace.Get((prefix.Length == 0) ? string.Empty : namespaceName).GetName(localName);
175 _attrValue = string.Empty;
176 }
177
178 public override void WriteStartDocument()
179 {
180 }
181
182 public override void WriteStartDocument(bool standalone)
183 {
184 }
185
186 public override void WriteStartElement(string prefix, string localName, string namespaceName)
187 {
188 AddNode(new XElement(XNamespace.Get(namespaceName).GetName(localName)));
189 }
190
191 public override void WriteString(string text)
192 {
194 }
195
196 public override void WriteSurrogateCharEntity(char lowCh, char highCh)
197 {
198 Span<char> span = stackalloc char[2] { highCh, lowCh };
200 AddString(new string(value));
201 }
202
203 public override void WriteValue(DateTimeOffset value)
204 {
206 }
207
208 public override void WriteWhitespace(string ws)
209 {
210 AddString(ws);
211 }
212
213 private void Add(object o)
214 {
215 if (_content == null)
216 {
217 _content = new List<object>();
218 }
219 _content.Add(o);
220 }
221
222 private void AddNode(XNode n)
223 {
224 if (_parent != null)
225 {
226 _parent.Add(n);
227 }
228 else
229 {
230 Add(n);
231 }
232 if (n is XContainer parent)
233 {
234 _parent = parent;
235 }
236 }
237
238 private void AddString(string s)
239 {
240 if (s != null)
241 {
242 if (_attrValue != null)
243 {
244 _attrValue += s;
245 }
246 else if (_parent != null)
247 {
248 _parent.Add(s);
249 }
250 else
251 {
252 Add(s);
253 }
254 }
255 }
256}
void Add(TKey key, TValue value)
static string NotSupported_WriteBase64
Definition SR.cs:64
static string NotSupported_WriteEntityRef
Definition SR.cs:66
Definition SR.cs:7
void Add(object? content)
static XNamespace Get(string namespaceName)
Definition XNamespace.cs:51
override void WriteRaw(char[] buffer, int index, int count)
override void WriteEntityRef(string name)
override void WriteEndElement()
override void WriteString(string text)
override void WriteCharEntity(char ch)
override void WriteSurrogateCharEntity(char lowCh, char highCh)
override XmlWriterSettings Settings
override void WriteEndAttribute()
override void WriteStartDocument(bool standalone)
override void WriteChars(char[] buffer, int index, int count)
override void WriteStartElement(string prefix, string localName, string namespaceName)
override void WriteProcessingInstruction(string name, string text)
XNodeBuilder(XContainer container)
override void WriteDocType(string name, string pubid, string sysid, string subset)
override void WriteStartAttribute(string prefix, string localName, string namespaceName)
override void WriteCData(string text)
override void WriteBase64(byte[] buffer, int index, int count)
readonly XContainer _root
override void WriteFullEndElement()
override string LookupPrefix(string namespaceName)
override void WriteValue(DateTimeOffset value)
override void Dispose(bool disposing)
override void WriteComment(string text)
override void WriteEndDocument()
override void WriteRaw(string data)
override void WriteStartDocument()
override void WriteWhitespace(string ws)
XContainer parent
Definition XObject.cs:7
static string ToString(bool value)