Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XObject.cs
Go to the documentation of this file.
2
3namespace System.Xml.Linq;
4
5public abstract class XObject : IXmlLineInfo
6{
7 internal XContainer parent;
8
9 internal object annotations;
10
11 public string BaseUri
12 {
13 get
14 {
15 XObject xObject = this;
16 while (true)
17 {
18 if (xObject != null && xObject.annotations == null)
19 {
20 xObject = xObject.parent;
21 continue;
22 }
23 if (xObject == null)
24 {
25 break;
26 }
28 if (baseUriAnnotation != null)
29 {
30 return baseUriAnnotation.baseUri;
31 }
32 xObject = xObject.parent;
33 }
34 return string.Empty;
35 }
36 }
37
39 {
40 get
41 {
42 XObject xObject = this;
43 while (xObject.parent != null)
44 {
45 xObject = xObject.parent;
46 }
47 return xObject as XDocument;
48 }
49 }
50
51 public abstract XmlNodeType NodeType { get; }
52
54
56
58
59 internal bool HasBaseUri => Annotation<BaseUriAnnotation>() != null;
60
94
128
129 internal XObject()
130 {
131 }
132
133 public void AddAnnotation(object annotation)
134 {
135 if (annotation == null)
136 {
137 throw new ArgumentNullException("annotation");
138 }
139 if (annotations == null)
140 {
141 annotations = ((!(annotation is object[])) ? annotation : new object[1] { annotation });
142 return;
143 }
144 object[] array = annotations as object[];
145 if (array == null)
146 {
147 annotations = new object[2] { annotations, annotation };
148 return;
149 }
150 int i;
151 for (i = 0; i < array.Length && array[i] != null; i++)
152 {
153 }
154 if (i == array.Length)
155 {
156 Array.Resize(ref array, i * 2);
158 }
159 array[i] = annotation;
160 }
161
162 public object? Annotation(Type type)
163 {
164 if (type == null)
165 {
166 throw new ArgumentNullException("type");
167 }
168 if (annotations != null)
169 {
170 if (!(annotations is object[] array))
171 {
173 {
174 return annotations;
175 }
176 }
177 else
178 {
179 foreach (object obj in array)
180 {
181 if (obj == null)
182 {
183 break;
184 }
186 {
187 return obj;
188 }
189 }
190 }
191 }
192 return null;
193 }
194
196 {
197 if (annotations != null)
198 {
199 if (!(annotations is object[] array))
200 {
201 if (annotations.GetType() == type)
202 {
203 return annotations;
204 }
205 }
206 else
207 {
208 foreach (object obj in array)
209 {
210 if (obj == null)
211 {
212 break;
213 }
214 if (obj.GetType() == type)
215 {
216 return obj;
217 }
218 }
219 }
220 }
221 return null;
222 }
223
224 public T? Annotation<T>() where T : class
225 {
226 if (annotations != null)
227 {
228 if (!(annotations is object[] array))
229 {
230 return annotations as T;
231 }
232 foreach (object obj in array)
233 {
234 if (obj == null)
235 {
236 break;
237 }
238 if (obj is T result)
239 {
240 return result;
241 }
242 }
243 }
244 return null;
245 }
246
248 {
249 if (type == null)
250 {
251 throw new ArgumentNullException("type");
252 }
254 }
255
257 {
258 if (annotations == null)
259 {
260 yield break;
261 }
262 if (!(annotations is object[] a))
263 {
265 {
266 yield return annotations;
267 }
268 yield break;
269 }
270 foreach (object obj in a)
271 {
272 if (obj != null)
273 {
275 {
276 yield return obj;
277 }
278 continue;
279 }
280 break;
281 }
282 }
283
285 {
286 if (annotations == null)
287 {
288 yield break;
289 }
290 if (!(annotations is object[] a))
291 {
292 if (annotations is T val)
293 {
294 yield return val;
295 }
296 yield break;
297 }
298 foreach (object obj in a)
299 {
300 if (obj != null)
301 {
302 if (obj is T val2)
303 {
304 yield return val2;
305 }
306 continue;
307 }
308 break;
309 }
310 }
311
313 {
314 if (type == null)
315 {
316 throw new ArgumentNullException("type");
317 }
318 if (annotations == null)
319 {
320 return;
321 }
322 if (!(annotations is object[] array))
323 {
325 {
326 annotations = null;
327 }
328 return;
329 }
330 int i = 0;
331 int num = 0;
332 for (; i < array.Length; i++)
333 {
334 object obj = array[i];
335 if (obj == null)
336 {
337 break;
338 }
340 {
341 array[num++] = obj;
342 }
343 }
344 if (num == 0)
345 {
346 annotations = null;
347 return;
348 }
349 while (num < i)
350 {
351 array[num++] = null;
352 }
353 }
354
356 {
357 if (annotations == null)
358 {
359 return;
360 }
361 if (!(annotations is object[] array))
362 {
363 if (annotations is T)
364 {
365 annotations = null;
366 }
367 return;
368 }
369 int i = 0;
370 int num = 0;
371 for (; i < array.Length; i++)
372 {
373 object obj = array[i];
374 if (obj == null)
375 {
376 break;
377 }
378 if (!(obj is T))
379 {
380 array[num++] = obj;
381 }
382 }
383 if (num == 0)
384 {
385 annotations = null;
386 return;
387 }
388 while (num < i)
389 {
390 array[num++] = null;
391 }
392 }
393
395 {
396 return Annotation<LineInfoAnnotation>() != null;
397 }
398
399 internal bool NotifyChanged(object sender, XObjectChangeEventArgs e)
400 {
401 bool result = false;
402 XObject xObject = this;
403 while (true)
404 {
405 if (xObject != null && xObject.annotations == null)
406 {
407 xObject = xObject.parent;
408 continue;
409 }
410 if (xObject == null)
411 {
412 break;
413 }
415 if (xObjectChangeAnnotation != null)
416 {
417 result = true;
418 if (xObjectChangeAnnotation.changed != null)
419 {
420 xObjectChangeAnnotation.changed(sender, e);
421 }
422 }
423 xObject = xObject.parent;
424 }
425 return result;
426 }
427
428 internal bool NotifyChanging(object sender, XObjectChangeEventArgs e)
429 {
430 bool result = false;
431 XObject xObject = this;
432 while (true)
433 {
434 if (xObject != null && xObject.annotations == null)
435 {
436 xObject = xObject.parent;
437 continue;
438 }
439 if (xObject == null)
440 {
441 break;
442 }
444 if (xObjectChangeAnnotation != null)
445 {
446 result = true;
447 if (xObjectChangeAnnotation.changing != null)
448 {
449 xObjectChangeAnnotation.changing(sender, e);
450 }
451 }
452 xObject = xObject.parent;
453 }
454 return result;
455 }
456
457 internal void SetBaseUri(string baseUri)
458 {
459 AddAnnotation(new BaseUriAnnotation(baseUri));
460 }
461
462 internal void SetLineInfo(int lineNumber, int linePosition)
463 {
464 AddAnnotation(new LineInfoAnnotation(lineNumber, linePosition));
465 }
466
467 internal bool SkipNotify()
468 {
469 XObject xObject = this;
470 while (true)
471 {
472 if (xObject != null && xObject.annotations == null)
473 {
474 xObject = xObject.parent;
475 continue;
476 }
477 if (xObject == null)
478 {
479 return true;
480 }
481 if (xObject.Annotation<XObjectChangeAnnotation>() != null)
482 {
483 break;
484 }
485 xObject = xObject.parent;
486 }
487 return false;
488 }
489
491 {
492 XObject xObject = this;
493 object obj;
494 while (true)
495 {
496 if (xObject != null && xObject.annotations == null)
497 {
498 xObject = xObject.parent;
499 continue;
500 }
501 if (xObject == null)
502 {
503 return SaveOptions.None;
504 }
505 obj = xObject.AnnotationForSealedType(typeof(SaveOptions));
506 if (obj != null)
507 {
508 break;
509 }
510 xObject = xObject.parent;
511 }
512 return (SaveOptions)obj;
513 }
514}
static ? Delegate Remove(Delegate? source, Delegate? value)
Definition Delegate.cs:463
static ? Delegate Combine(Delegate? a, Delegate? b)
Definition Delegate.cs:379
static bool IsInstanceOfType(object o, Type type)
Definition XHelper.cs:5
IEnumerable< object > Annotations(Type type)
Definition XObject.cs:247
XmlNodeType NodeType
Definition XObject.cs:51
EventHandler< XObjectChangeEventArgs > Changed
Definition XObject.cs:62
object AnnotationForSealedType(Type type)
Definition XObject.cs:195
void RemoveAnnotations< T >()
Definition XObject.cs:355
XContainer parent
Definition XObject.cs:7
XDocument? Document
Definition XObject.cs:39
IEnumerable< object > AnnotationsIterator(Type type)
Definition XObject.cs:256
bool NotifyChanging(object sender, XObjectChangeEventArgs e)
Definition XObject.cs:428
object? Annotation(Type type)
Definition XObject.cs:162
SaveOptions GetSaveOptionsFromAnnotations()
Definition XObject.cs:490
void AddAnnotation(object annotation)
Definition XObject.cs:133
void SetLineInfo(int lineNumber, int linePosition)
Definition XObject.cs:462
bool NotifyChanged(object sender, XObjectChangeEventArgs e)
Definition XObject.cs:399
EventHandler< XObjectChangeEventArgs > Changing
Definition XObject.cs:96
void RemoveAnnotations(Type type)
Definition XObject.cs:312
void SetBaseUri(string baseUri)
Definition XObject.cs:457
IEnumerable< T > Annotations< T >()
Definition XObject.cs:284