Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlSerializationWriter.cs
Go to the documentation of this file.
6using System.Text;
8
10
12{
13 internal sealed class TypeEntry
14 {
15 internal XmlSerializationWriteCallback callback;
16
17 internal string typeNs;
18
19 internal string typeName;
20
21 internal Type type;
22 }
23
24 private XmlWriter _w;
25
27
29
31
33
34 private string _idBase;
35
36 private int _nextId;
37
39
41
43
44 private readonly string _aliasBase = "q";
45
46 private bool _soap12;
47
48 private bool _escapeName = true;
49
50 protected bool EscapeName
51 {
52 get
53 {
54 return _escapeName;
55 }
56 set
57 {
59 }
60 }
61
62 protected XmlWriter Writer
63 {
64 get
65 {
66 return _w;
67 }
68 set
69 {
70 _w = value;
71 }
72 }
73
75 {
76 get
77 {
78 if (_namespaces != null)
79 {
81 }
82 return null;
83 }
84 set
85 {
86 if (value == null)
87 {
88 _namespaces = null;
89 return;
90 }
93 }
94 }
95
97 {
98 _w = w;
100 _soap12 = encodingStyle == "http://www.w3.org/2003/05/soap-encoding";
101 _idBase = idBase;
103 }
104
105 protected static byte[] FromByteArrayBase64(byte[] value)
106 {
107 return value;
108 }
109
111 {
113 }
114
115 [return: NotNullIfNotNull("value")]
116 protected static string? FromByteArrayHex(byte[]? value)
117 {
119 }
120
121 protected static string FromDateTime(DateTime value)
122 {
124 }
125
126 protected static string FromDate(DateTime value)
127 {
129 }
130
131 protected static string FromTime(DateTime value)
132 {
134 }
135
136 protected static string FromChar(char value)
137 {
139 }
140
141 protected static string FromEnum(long value, string[] values, long[] ids)
142 {
144 }
145
146 protected static string FromEnum(long value, string[] values, long[] ids, string typeName)
147 {
148 return XmlCustomFormatter.FromEnum(value, values, ids, typeName);
149 }
150
151 [return: NotNullIfNotNull("name")]
152 protected static string? FromXmlName(string? name)
153 {
154 return XmlCustomFormatter.FromXmlName(name);
155 }
156
157 [return: NotNullIfNotNull("ncName")]
158 protected static string? FromXmlNCName(string? ncName)
159 {
160 return XmlCustomFormatter.FromXmlNCName(ncName);
161 }
162
163 [return: NotNullIfNotNull("nmToken")]
164 protected static string? FromXmlNmToken(string? nmToken)
165 {
167 }
168
169 [return: NotNullIfNotNull("nmTokens")]
170 protected static string? FromXmlNmTokens(string? nmTokens)
171 {
173 }
174
175 protected void WriteXsiType(string name, string? ns)
176 {
177 WriteAttribute("type", "http://www.w3.org/2001/XMLSchema-instance", GetQualifiedName(name, ns));
178 }
179
180 [RequiresUnreferencedCode("calls GetPrimitiveTypeName")]
185
186 [RequiresUnreferencedCode("calls CreateUnknownTypeException")]
196
198 {
199 string ns = "http://www.w3.org/2001/XMLSchema";
200 string name;
201 switch (Type.GetTypeCode(type))
202 {
203 case TypeCode.String:
204 name = "string";
205 break;
206 case TypeCode.Int32:
207 name = "int";
208 break;
209 case TypeCode.Boolean:
210 name = "boolean";
211 break;
212 case TypeCode.Int16:
213 name = "short";
214 break;
215 case TypeCode.Int64:
216 name = "long";
217 break;
218 case TypeCode.Single:
219 name = "float";
220 break;
221 case TypeCode.Double:
222 name = "double";
223 break;
224 case TypeCode.Decimal:
225 name = "decimal";
226 break;
227 case TypeCode.DateTime:
228 name = "dateTime";
229 break;
230 case TypeCode.Byte:
231 name = "unsignedByte";
232 break;
233 case TypeCode.SByte:
234 name = "byte";
235 break;
236 case TypeCode.UInt16:
237 name = "unsignedShort";
238 break;
239 case TypeCode.UInt32:
240 name = "unsignedInt";
241 break;
242 case TypeCode.UInt64:
243 name = "unsignedLong";
244 break;
245 case TypeCode.Char:
246 name = "char";
247 ns = "http://microsoft.com/wsdl/types/";
248 break;
249 default:
251 {
252 name = "QName";
253 break;
254 }
255 if (type == typeof(byte[]))
256 {
257 name = "base64Binary";
258 break;
259 }
260 if (type == typeof(Guid))
261 {
262 name = "guid";
263 ns = "http://microsoft.com/wsdl/types/";
264 break;
265 }
266 if (type == typeof(TimeSpan))
267 {
268 name = "TimeSpan";
269 ns = "http://microsoft.com/wsdl/types/";
270 break;
271 }
272 if (type == typeof(DateTimeOffset))
273 {
274 name = "dateTimeOffset";
275 ns = "http://microsoft.com/wsdl/types/";
276 break;
277 }
278 if (type == typeof(XmlNode[]))
279 {
280 name = "anyType";
281 break;
282 }
283 return null;
284 }
285 return new XmlQualifiedName(name, ns);
286 }
287
288 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly")]
289 protected void WriteTypedPrimitive(string? name, string? ns, object o, bool xsiType)
290 {
291 string text = null;
292 string ns2 = "http://www.w3.org/2001/XMLSchema";
293 bool flag = true;
294 bool flag2 = false;
295 Type type = o.GetType();
296 bool flag3 = false;
297 string text2;
298 switch (Type.GetTypeCode(type))
299 {
300 case TypeCode.String:
301 text = (string)o;
302 text2 = "string";
303 flag = false;
304 break;
305 case TypeCode.Int32:
306 text = XmlConvert.ToString((int)o);
307 text2 = "int";
308 break;
309 case TypeCode.Boolean:
310 text = XmlConvert.ToString((bool)o);
311 text2 = "boolean";
312 break;
313 case TypeCode.Int16:
314 text = XmlConvert.ToString((short)o);
315 text2 = "short";
316 break;
317 case TypeCode.Int64:
318 text = XmlConvert.ToString((long)o);
319 text2 = "long";
320 break;
321 case TypeCode.Single:
322 text = XmlConvert.ToString((float)o);
323 text2 = "float";
324 break;
325 case TypeCode.Double:
326 text = XmlConvert.ToString((double)o);
327 text2 = "double";
328 break;
329 case TypeCode.Decimal:
330 text = XmlConvert.ToString((decimal)o);
331 text2 = "decimal";
332 break;
333 case TypeCode.DateTime:
335 text2 = "dateTime";
336 break;
337 case TypeCode.Char:
338 text = FromChar((char)o);
339 text2 = "char";
340 ns2 = "http://microsoft.com/wsdl/types/";
341 break;
342 case TypeCode.Byte:
343 text = XmlConvert.ToString((byte)o);
344 text2 = "unsignedByte";
345 break;
346 case TypeCode.SByte:
347 text = XmlConvert.ToString((sbyte)o);
348 text2 = "byte";
349 break;
350 case TypeCode.UInt16:
351 text = XmlConvert.ToString((ushort)o);
352 text2 = "unsignedShort";
353 break;
354 case TypeCode.UInt32:
355 text = XmlConvert.ToString((uint)o);
356 text2 = "unsignedInt";
357 break;
358 case TypeCode.UInt64:
359 text = XmlConvert.ToString((ulong)o);
360 text2 = "unsignedLong";
361 break;
362 default:
364 {
365 text2 = "QName";
366 flag3 = true;
367 if (name == null)
368 {
370 }
371 else
372 {
373 _w.WriteStartElement(name, ns);
374 }
376 break;
377 }
378 if (type == typeof(byte[]))
379 {
380 text = string.Empty;
381 flag2 = true;
382 text2 = "base64Binary";
383 break;
384 }
385 if (type == typeof(Guid))
386 {
388 text2 = "guid";
389 ns2 = "http://microsoft.com/wsdl/types/";
390 break;
391 }
392 if (type == typeof(TimeSpan))
393 {
395 text2 = "TimeSpan";
396 ns2 = "http://microsoft.com/wsdl/types/";
397 break;
398 }
399 if (type == typeof(DateTimeOffset))
400 {
402 text2 = "dateTimeOffset";
403 ns2 = "http://microsoft.com/wsdl/types/";
404 break;
405 }
406 if (typeof(XmlNode[]).IsAssignableFrom(type))
407 {
408 if (name == null)
409 {
410 _w.WriteStartElement("anyType", "http://www.w3.org/2001/XMLSchema");
411 }
412 else
413 {
414 _w.WriteStartElement(name, ns);
415 }
416 XmlNode[] array = (XmlNode[])o;
417 for (int i = 0; i < array.Length; i++)
418 {
419 if (array[i] != null)
420 {
421 array[i].WriteTo(_w);
422 }
423 }
425 return;
426 }
428 }
429 if (!flag3)
430 {
431 if (name == null)
432 {
434 }
435 else
436 {
437 _w.WriteStartElement(name, ns);
438 }
439 }
440 if (xsiType)
441 {
443 }
444 if (text == null)
445 {
446 _w.WriteAttributeString("nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
447 }
448 else if (flag2)
449 {
450 XmlCustomFormatter.WriteArrayBase64(_w, (byte[])o, 0, ((byte[])o).Length);
451 }
452 else if (flag)
453 {
455 }
456 else
457 {
459 }
461 }
462
463 private string GetQualifiedName(string name, string ns)
464 {
465 if (ns == null || ns.Length == 0)
466 {
467 return name;
468 }
469 string text = _w.LookupPrefix(ns);
470 if (text == null)
471 {
472 if (ns == "http://www.w3.org/XML/1998/namespace")
473 {
474 text = "xml";
475 }
476 else
477 {
478 text = NextPrefix();
479 WriteAttribute("xmlns", text, null, ns);
480 }
481 }
482 else if (text.Length == 0)
483 {
484 return name;
485 }
486 return text + ":" + name;
487 }
488
493
495 {
496 if (xmlQualifiedName == null)
497 {
498 return null;
499 }
500 if (xmlQualifiedName.IsEmpty && ignoreEmpty)
501 {
502 return null;
503 }
505 }
506
507 protected void WriteStartElement(string name)
508 {
509 WriteStartElement(name, null, null, writePrefixed: false, null);
510 }
511
512 protected void WriteStartElement(string name, string? ns)
513 {
514 WriteStartElement(name, ns, null, writePrefixed: false, null);
515 }
516
517 protected void WriteStartElement(string name, string? ns, bool writePrefixed)
518 {
519 WriteStartElement(name, ns, null, writePrefixed, null);
520 }
521
522 protected void WriteStartElement(string name, string? ns, object? o)
523 {
524 WriteStartElement(name, ns, o, writePrefixed: false, null);
525 }
526
527 protected void WriteStartElement(string name, string? ns, object? o, bool writePrefixed)
528 {
529 WriteStartElement(name, ns, o, writePrefixed, null);
530 }
531
532 protected void WriteStartElement(string name, string? ns, object? o, bool writePrefixed, XmlSerializerNamespaces? xmlns)
533 {
534 if (o != null && _objectsInUse != null)
535 {
537 {
539 }
541 }
542 string prefix = null;
543 bool flag = false;
544 if (_namespaces != null)
545 {
548 {
549 if (string.IsNullOrEmpty(ns2))
550 {
551 flag = true;
552 }
553 if (ns != ns2)
554 {
555 writePrefixed = true;
556 }
557 }
559 }
560 if (writePrefixed && prefix == null && ns != null && ns.Length > 0)
561 {
562 prefix = _w.LookupPrefix(ns);
563 if (prefix == null || prefix.Length == 0)
564 {
565 prefix = NextPrefix();
566 }
567 }
568 if (prefix == null)
569 {
570 xmlns?.TryLookupPrefix(ns, out prefix);
571 }
572 if (flag && prefix == null && ns != null && ns.Length != 0)
573 {
574 prefix = NextPrefix();
575 }
576 _w.WriteStartElement(prefix, name, ns);
577 if (_namespaces != null)
578 {
580 {
581 string name2 = namespace2.Name;
582 string @namespace = namespace2.Namespace;
583 if (name2.Length == 0 && (@namespace == null || @namespace.Length == 0))
584 {
585 continue;
586 }
587 if (@namespace == null || @namespace.Length == 0)
588 {
589 if (name2.Length > 0)
590 {
592 }
593 WriteAttribute("xmlns", name2, null, @namespace);
594 }
595 else if (_w.LookupPrefix(@namespace) == null)
596 {
597 if (prefix == null && name2.Length == 0)
598 {
599 break;
600 }
601 WriteAttribute("xmlns", name2, null, @namespace);
602 }
603 }
604 }
606 }
607
609 {
611 int length = prefix.Length;
612 foreach (XmlQualifiedName @namespace in nsList.Namespaces)
613 {
614 if (@namespace.Name.Length <= length)
615 {
616 continue;
617 }
618 string name = @namespace.Name;
619 if (name.Length <= length || name.Length > length + "2147483647".Length || !name.StartsWith(prefix, StringComparison.Ordinal))
620 {
621 continue;
622 }
623 bool flag = true;
624 for (int i = length; i < name.Length; i++)
625 {
626 if (!char.IsDigit(name, i))
627 {
628 flag = false;
629 break;
630 }
631 }
632 if (flag)
633 {
634 long num = long.Parse(name.AsSpan(length), NumberStyles.Integer, CultureInfo.InvariantCulture);
635 if (num <= int.MaxValue)
636 {
637 int item = (int)num;
639 }
640 }
641 }
642 if (hashSet.Count > 0)
643 {
644 return hashSet;
645 }
646 return null;
647 }
648
649 protected void WriteNullTagEncoded(string? name)
650 {
651 WriteNullTagEncoded(name, null);
652 }
653
654 protected void WriteNullTagEncoded(string? name, string? ns)
655 {
656 if (name != null && name.Length != 0)
657 {
658 WriteStartElement(name, ns, null, writePrefixed: true);
659 _w.WriteAttributeString("nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
661 }
662 }
663
664 protected void WriteNullTagLiteral(string? name)
665 {
666 WriteNullTagLiteral(name, null);
667 }
668
669 protected void WriteNullTagLiteral(string? name, string? ns)
670 {
671 if (name != null && name.Length != 0)
672 {
673 WriteStartElement(name, ns, null, writePrefixed: false);
674 _w.WriteAttributeString("nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
676 }
677 }
678
679 protected void WriteEmptyTag(string? name)
680 {
681 WriteEmptyTag(name, null);
682 }
683
684 protected void WriteEmptyTag(string? name, string? ns)
685 {
686 if (name != null && name.Length != 0)
687 {
688 WriteStartElement(name, ns, null, writePrefixed: false);
690 }
691 }
692
693 protected void WriteEndElement()
694 {
696 }
697
698 protected void WriteEndElement(object? o)
699 {
701 if (o != null && _objectsInUse != null)
702 {
704 }
705 }
706
707 protected void WriteSerializable(IXmlSerializable? serializable, string name, string ns, bool isNullable)
708 {
710 }
711
712 protected void WriteSerializable(IXmlSerializable? serializable, string name, string? ns, bool isNullable, bool wrapped)
713 {
714 if (serializable == null)
715 {
716 if (isNullable)
717 {
718 WriteNullTagLiteral(name, ns);
719 }
720 return;
721 }
722 if (wrapped)
723 {
724 _w.WriteStartElement(name, ns);
725 }
726 serializable.WriteXml(_w);
727 if (wrapped)
728 {
730 }
731 }
732
733 protected void WriteNullableStringEncoded(string name, string? ns, string? value, XmlQualifiedName? xsiType)
734 {
735 if (value == null)
736 {
737 WriteNullTagEncoded(name, ns);
738 }
739 else
740 {
741 WriteElementString(name, ns, value, xsiType);
742 }
743 }
744
745 protected void WriteNullableStringLiteral(string name, string? ns, string? value)
746 {
747 if (value == null)
748 {
749 WriteNullTagLiteral(name, ns);
750 }
751 else
752 {
753 WriteElementString(name, ns, value, null);
754 }
755 }
756
757 protected void WriteNullableStringEncodedRaw(string name, string? ns, string? value, XmlQualifiedName? xsiType)
758 {
759 if (value == null)
760 {
761 WriteNullTagEncoded(name, ns);
762 }
763 else
764 {
766 }
767 }
768
769 protected void WriteNullableStringEncodedRaw(string name, string? ns, byte[]? value, XmlQualifiedName? xsiType)
770 {
771 if (value == null)
772 {
773 WriteNullTagEncoded(name, ns);
774 }
775 else
776 {
778 }
779 }
780
781 protected void WriteNullableStringLiteralRaw(string name, string? ns, string? value)
782 {
783 if (value == null)
784 {
785 WriteNullTagLiteral(name, ns);
786 }
787 else
788 {
789 WriteElementStringRaw(name, ns, value, null);
790 }
791 }
792
793 protected void WriteNullableStringLiteralRaw(string name, string? ns, byte[]? value)
794 {
795 if (value == null)
796 {
797 WriteNullTagLiteral(name, ns);
798 }
799 else
800 {
801 WriteElementStringRaw(name, ns, value, null);
802 }
803 }
804
806 {
807 if (value == null)
808 {
809 WriteNullTagEncoded(name, ns);
810 }
811 else
812 {
814 }
815 }
816
817 protected void WriteNullableQualifiedNameLiteral(string name, string? ns, XmlQualifiedName? value)
818 {
819 if (value == null)
820 {
821 WriteNullTagLiteral(name, ns);
822 }
823 else
824 {
825 WriteElementQualifiedName(name, ns, value, null);
826 }
827 }
828
829 protected void WriteElementEncoded(XmlNode? node, string name, string? ns, bool isNullable, bool any)
830 {
831 if (node == null)
832 {
833 if (isNullable)
834 {
835 WriteNullTagEncoded(name, ns);
836 }
837 }
838 else
839 {
840 WriteElement(node, name, ns, isNullable, any);
841 }
842 }
843
844 protected void WriteElementLiteral(XmlNode? node, string name, string? ns, bool isNullable, bool any)
845 {
846 if (node == null)
847 {
848 if (isNullable)
849 {
850 WriteNullTagLiteral(name, ns);
851 }
852 }
853 else
854 {
855 WriteElement(node, name, ns, isNullable, any);
856 }
857 }
858
859 private void WriteElement(XmlNode node, string name, string ns, bool isNullable, bool any)
860 {
861 if (typeof(XmlAttribute).IsAssignableFrom(node.GetType()))
862 {
864 }
865 if (node is XmlDocument)
866 {
867 node = ((XmlDocument)node).DocumentElement;
868 if (node == null)
869 {
870 if (isNullable)
871 {
872 WriteNullTagEncoded(name, ns);
873 }
874 return;
875 }
876 }
877 if (any)
878 {
879 if (node is XmlElement && name != null && name.Length > 0 && (node.LocalName != name || node.NamespaceURI != ns))
880 {
881 throw new InvalidOperationException(System.SR.Format(System.SR.XmlElementNameMismatch, node.LocalName, node.NamespaceURI, name, ns));
882 }
883 }
884 else
885 {
886 _w.WriteStartElement(name, ns);
887 }
888 node.WriteTo(_w);
889 if (!any)
890 {
892 }
893 }
894
895 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly")]
897 {
898 return CreateUnknownTypeException(o.GetType());
899 }
900
901 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly")]
903 {
904 if (typeof(IXmlSerializable).IsAssignableFrom(type))
905 {
907 }
909 if (!typeDesc.IsStructLike)
910 {
912 }
914 }
915
916 protected Exception CreateMismatchChoiceException(string value, string elementName, string enumValue)
917 {
919 }
920
921 protected Exception CreateUnknownAnyElementException(string name, string ns)
922 {
924 }
925
930
931 protected Exception CreateChoiceIdentifierValueException(string value, string identifier, string name, string ns)
932 {
934 }
935
936 protected Exception CreateInvalidEnumValueException(object value, string typeName)
937 {
939 }
940
942 {
943 return CreateInvalidAnyTypeException(o.GetType());
944 }
945
950
951 protected void WriteReferencingElement(string n, string? ns, object? o)
952 {
954 }
955
956 protected void WriteReferencingElement(string n, string? ns, object? o, bool isNullable)
957 {
958 if (o == null)
959 {
960 if (isNullable)
961 {
963 }
964 return;
965 }
966 WriteStartElement(n, ns, null, writePrefixed: true);
967 if (_soap12)
968 {
969 _w.WriteAttributeString("ref", "http://www.w3.org/2003/05/soap-encoding", GetId(o, addToReferencesList: true));
970 }
971 else
972 {
973 _w.WriteAttributeString("href", "#" + GetId(o, addToReferencesList: true));
974 }
976 }
977
978 private bool IsIdDefined(object o)
979 {
980 if (_references != null)
981 {
982 return _references.Contains(o);
983 }
984 return false;
985 }
986
987 private string GetId(object o, bool addToReferencesList)
988 {
989 if (_references == null)
990 {
991 _references = new Hashtable();
993 }
994 string text = (string)_references[o];
995 if (text == null)
996 {
997 string idBase = _idBase;
998 int num = ++_nextId;
999 text = idBase + "id" + num.ToString(CultureInfo.InvariantCulture);
1002 {
1004 }
1005 }
1006 return text;
1007 }
1008
1009 protected void WriteId(object o)
1010 {
1012 }
1013
1014 private void WriteId(object o, bool addToReferencesList)
1015 {
1016 if (_soap12)
1017 {
1018 _w.WriteAttributeString("id", "http://www.w3.org/2003/05/soap-encoding", GetId(o, addToReferencesList));
1019 }
1020 else
1021 {
1023 }
1024 }
1025
1027 {
1028 WriteXmlAttribute(node, null);
1029 }
1030
1031 protected void WriteXmlAttribute(XmlNode node, object? container)
1032 {
1034 {
1036 }
1037 if (xmlAttribute.Value != null)
1038 {
1039 if (xmlAttribute.NamespaceURI == "http://schemas.xmlsoap.org/wsdl/" && xmlAttribute.LocalName == "arrayType")
1040 {
1041 string dims;
1044 WriteAttribute("arrayType", "http://schemas.xmlsoap.org/wsdl/", value);
1045 }
1046 else
1047 {
1048 WriteAttribute(xmlAttribute.Name, xmlAttribute.NamespaceURI, xmlAttribute.Value);
1049 }
1050 }
1051 }
1052
1053 protected void WriteAttribute(string localName, string? ns, string? value)
1054 {
1055 if (value == null || !(localName != "xmlns") || localName.StartsWith("xmlns:", StringComparison.Ordinal))
1056 {
1057 return;
1058 }
1059 int num = localName.IndexOf(':');
1060 if (num < 0)
1061 {
1062 if (ns == "http://www.w3.org/XML/1998/namespace")
1063 {
1064 string text = _w.LookupPrefix(ns);
1065 if (text == null || text.Length == 0)
1066 {
1067 text = "xml";
1068 }
1069 _w.WriteAttributeString(text, localName, ns, value);
1070 }
1071 else
1072 {
1073 _w.WriteAttributeString(localName, ns, value);
1074 }
1075 }
1076 else
1077 {
1078 string prefix = localName.Substring(0, num);
1079 _w.WriteAttributeString(prefix, localName.Substring(num + 1), ns, value);
1080 }
1081 }
1082
1083 protected void WriteAttribute(string localName, string ns, byte[]? value)
1084 {
1085 if (value == null || !(localName != "xmlns") || localName.StartsWith("xmlns:", StringComparison.Ordinal))
1086 {
1087 return;
1088 }
1089 int num = localName.IndexOf(':');
1090 if (num < 0)
1091 {
1092 if (ns == "http://www.w3.org/XML/1998/namespace")
1093 {
1094 string text = _w.LookupPrefix(ns);
1095 if (text == null || text.Length == 0)
1096 {
1097 text = "xml";
1098 }
1099 _w.WriteStartAttribute("xml", localName, ns);
1100 }
1101 else
1102 {
1103 _w.WriteStartAttribute(null, localName, ns);
1104 }
1105 }
1106 else
1107 {
1108 string prefix = _w.LookupPrefix(ns);
1109 _w.WriteStartAttribute(prefix, localName.Substring(num + 1), ns);
1110 }
1113 }
1114
1115 protected void WriteAttribute(string localName, string? value)
1116 {
1117 if (value != null)
1118 {
1119 _w.WriteAttributeString(localName, null, value);
1120 }
1121 }
1122
1123 protected void WriteAttribute(string localName, byte[]? value)
1124 {
1125 if (value != null)
1126 {
1127 _w.WriteStartAttribute(null, localName, null);
1130 }
1131 }
1132
1133 protected void WriteAttribute(string? prefix, string localName, string? ns, string? value)
1134 {
1135 if (value != null)
1136 {
1137 _w.WriteAttributeString(prefix, localName, null, value);
1138 }
1139 }
1140
1141 protected void WriteValue(string? value)
1142 {
1143 if (value != null)
1144 {
1146 }
1147 }
1148
1149 protected void WriteValue(byte[]? value)
1150 {
1151 if (value != null)
1152 {
1154 }
1155 }
1156
1157 protected void WriteStartDocument()
1158 {
1159 if (_w.WriteState == WriteState.Start)
1160 {
1162 }
1163 }
1164
1165 protected void WriteElementString(string localName, string? value)
1166 {
1167 WriteElementString(localName, null, value, null);
1168 }
1169
1170 protected void WriteElementString(string localName, string? ns, string? value)
1171 {
1172 WriteElementString(localName, ns, value, null);
1173 }
1174
1175 protected void WriteElementString(string localName, string? value, XmlQualifiedName? xsiType)
1176 {
1177 WriteElementString(localName, null, value, xsiType);
1178 }
1179
1180 protected void WriteElementString(string localName, string? ns, string? value, XmlQualifiedName? xsiType)
1181 {
1182 if (value != null)
1183 {
1184 if (xsiType == null)
1185 {
1186 _w.WriteElementString(localName, ns, value);
1187 return;
1188 }
1189 _w.WriteStartElement(localName, ns);
1190 WriteXsiType(xsiType.Name, xsiType.Namespace);
1193 }
1194 }
1195
1196 protected void WriteElementStringRaw(string localName, string? value)
1197 {
1198 WriteElementStringRaw(localName, null, value, null);
1199 }
1200
1201 protected void WriteElementStringRaw(string localName, byte[]? value)
1202 {
1203 WriteElementStringRaw(localName, null, value, null);
1204 }
1205
1206 protected void WriteElementStringRaw(string localName, string? ns, string? value)
1207 {
1208 WriteElementStringRaw(localName, ns, value, null);
1209 }
1210
1211 protected void WriteElementStringRaw(string localName, string? ns, byte[]? value)
1212 {
1213 WriteElementStringRaw(localName, ns, value, null);
1214 }
1215
1216 protected void WriteElementStringRaw(string localName, string? value, XmlQualifiedName? xsiType)
1217 {
1218 WriteElementStringRaw(localName, null, value, xsiType);
1219 }
1220
1221 protected void WriteElementStringRaw(string localName, byte[]? value, XmlQualifiedName? xsiType)
1222 {
1223 WriteElementStringRaw(localName, null, value, xsiType);
1224 }
1225
1226 protected void WriteElementStringRaw(string localName, string? ns, string? value, XmlQualifiedName? xsiType)
1227 {
1228 if (value != null)
1229 {
1230 _w.WriteStartElement(localName, ns);
1231 if (xsiType != null)
1232 {
1233 WriteXsiType(xsiType.Name, xsiType.Namespace);
1234 }
1235 _w.WriteRaw(value);
1237 }
1238 }
1239
1240 protected void WriteElementStringRaw(string localName, string? ns, byte[]? value, XmlQualifiedName? xsiType)
1241 {
1242 if (value != null)
1243 {
1244 _w.WriteStartElement(localName, ns);
1245 if (xsiType != null)
1246 {
1247 WriteXsiType(xsiType.Name, xsiType.Namespace);
1248 }
1251 }
1252 }
1253
1254 protected void WriteRpcResult(string name, string? ns)
1255 {
1256 if (_soap12)
1257 {
1258 WriteElementQualifiedName("result", "http://www.w3.org/2003/05/soap-rpc", new XmlQualifiedName(name, ns), null);
1259 }
1260 }
1261
1262 protected void WriteElementQualifiedName(string localName, XmlQualifiedName? value)
1263 {
1264 WriteElementQualifiedName(localName, null, value, null);
1265 }
1266
1268 {
1269 WriteElementQualifiedName(localName, null, value, xsiType);
1270 }
1271
1272 protected void WriteElementQualifiedName(string localName, string? ns, XmlQualifiedName? value)
1273 {
1274 WriteElementQualifiedName(localName, ns, value, null);
1275 }
1276
1277 protected void WriteElementQualifiedName(string localName, string? ns, XmlQualifiedName? value, XmlQualifiedName? xsiType)
1278 {
1279 if (!(value == null))
1280 {
1281 if (value.Namespace == null || value.Namespace.Length == 0)
1282 {
1283 WriteStartElement(localName, ns, null, writePrefixed: true);
1284 WriteAttribute("xmlns", "");
1285 }
1286 else
1287 {
1288 _w.WriteStartElement(localName, ns);
1289 }
1290 if (xsiType != null)
1291 {
1292 WriteXsiType(xsiType.Name, xsiType.Namespace);
1293 }
1296 }
1297 }
1298
1299 protected void AddWriteCallback(Type type, string typeName, string? typeNs, XmlSerializationWriteCallback callback)
1300 {
1302 typeEntry.typeName = typeName;
1303 typeEntry.typeNs = typeNs;
1305 typeEntry.callback = callback;
1307 }
1308
1309 [RequiresUnreferencedCode("calls GetArrayElementType")]
1310 private void WriteArray(string name, string ns, object o, Type type)
1311 {
1314 if (!_soap12)
1315 {
1316 while ((arrayElementType.IsArray || typeof(IEnumerable).IsAssignableFrom(arrayElementType)) && GetPrimitiveTypeName(arrayElementType, throwIfUnknown: false) == null)
1317 {
1319 stringBuilder.Append("[]");
1320 }
1321 }
1322 string text;
1323 string ns2;
1324 if (arrayElementType == typeof(object))
1325 {
1326 text = "anyType";
1327 ns2 = "http://www.w3.org/2001/XMLSchema";
1328 }
1329 else
1330 {
1332 if (typeEntry != null)
1333 {
1334 text = typeEntry.typeName;
1335 ns2 = typeEntry.typeNs;
1336 }
1337 else if (_soap12)
1338 {
1340 if (primitiveTypeName != null)
1341 {
1342 text = primitiveTypeName.Name;
1343 ns2 = primitiveTypeName.Namespace;
1344 }
1345 else
1346 {
1347 Type baseType = arrayElementType.BaseType;
1348 while (baseType != null)
1349 {
1351 if (typeEntry != null)
1352 {
1353 break;
1354 }
1355 baseType = baseType.BaseType;
1356 }
1357 if (typeEntry != null)
1358 {
1359 text = typeEntry.typeName;
1360 ns2 = typeEntry.typeNs;
1361 }
1362 else
1363 {
1364 text = "anyType";
1365 ns2 = "http://www.w3.org/2001/XMLSchema";
1366 }
1367 }
1368 }
1369 else
1370 {
1372 text = primitiveTypeName2.Name;
1373 ns2 = primitiveTypeName2.Namespace;
1374 }
1375 }
1376 if (stringBuilder.Length > 0)
1377 {
1378 text += stringBuilder.ToString();
1379 }
1380 if (_soap12 && name != null && name.Length > 0)
1381 {
1382 WriteStartElement(name, ns, null, writePrefixed: false);
1383 }
1384 else
1385 {
1386 WriteStartElement("Array", "http://schemas.xmlsoap.org/soap/encoding/", null, writePrefixed: true);
1387 }
1388 WriteId(o, addToReferencesList: false);
1389 if (type.IsArray)
1390 {
1391 Array array = (Array)o;
1392 int length = array.Length;
1393 if (_soap12)
1394 {
1395 _w.WriteAttributeString("itemType", "http://www.w3.org/2003/05/soap-encoding", GetQualifiedName(text, ns2));
1396 _w.WriteAttributeString("arraySize", "http://www.w3.org/2003/05/soap-encoding", length.ToString(CultureInfo.InvariantCulture));
1397 }
1398 else
1399 {
1400 _w.WriteAttributeString("arrayType", "http://schemas.xmlsoap.org/soap/encoding/", $"{GetQualifiedName(text, ns2)}[{length}]");
1401 }
1402 for (int i = 0; i < length; i++)
1403 {
1405 }
1406 }
1407 else
1408 {
1409 int num = (typeof(ICollection).IsAssignableFrom(type) ? ((ICollection)o).Count : (-1));
1410 if (_soap12)
1411 {
1412 _w.WriteAttributeString("itemType", "http://www.w3.org/2003/05/soap-encoding", GetQualifiedName(text, ns2));
1413 if (num >= 0)
1414 {
1415 _w.WriteAttributeString("arraySize", "http://www.w3.org/2003/05/soap-encoding", num.ToString(CultureInfo.InvariantCulture));
1416 }
1417 }
1418 else
1419 {
1420 string text2 = ((num >= 0) ? ("[" + num + "]") : "[]");
1421 _w.WriteAttributeString("arrayType", "http://schemas.xmlsoap.org/soap/encoding/", GetQualifiedName(text, ns2) + text2);
1422 }
1424 if (enumerator != null)
1425 {
1426 while (enumerator.MoveNext())
1427 {
1429 }
1430 }
1431 }
1433 }
1434
1435 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly")]
1436 protected void WritePotentiallyReferencingElement(string? n, string? ns, object? o)
1437 {
1439 }
1440
1441 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly")]
1442 protected void WritePotentiallyReferencingElement(string? n, string? ns, object? o, Type? ambientType)
1443 {
1445 }
1446
1447 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly")]
1448 protected void WritePotentiallyReferencingElement(string n, string? ns, object? o, Type? ambientType, bool suppressReference)
1449 {
1451 }
1452
1453 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly")]
1454 protected void WritePotentiallyReferencingElement(string? n, string? ns, object? o, Type? ambientType, bool suppressReference, bool isNullable)
1455 {
1456 if (o == null)
1457 {
1458 if (isNullable)
1459 {
1461 }
1462 return;
1463 }
1464 Type type = o.GetType();
1465 if (Type.GetTypeCode(type) == TypeCode.Object && !(o is Guid) && type != typeof(XmlQualifiedName) && !(o is XmlNode[]) && type != typeof(byte[]))
1466 {
1467 if ((suppressReference || _soap12) && !IsIdDefined(o))
1468 {
1470 }
1471 else if (n == null)
1472 {
1475 }
1476 else
1477 {
1479 }
1480 return;
1481 }
1482 bool flag = type != ambientType && !type.IsEnum;
1484 if (typeEntry2 != null)
1485 {
1486 if (n == null)
1487 {
1488 WriteStartElement(typeEntry2.typeName, typeEntry2.typeNs, null, writePrefixed: true);
1489 }
1490 else
1491 {
1492 WriteStartElement(n, ns, null, writePrefixed: true);
1493 }
1494 if (flag)
1495 {
1496 WriteXsiType(typeEntry2.typeName, typeEntry2.typeNs);
1497 }
1498 typeEntry2.callback(o);
1500 }
1501 else
1502 {
1503 WriteTypedPrimitive(n, ns, o, flag);
1504 }
1505 }
1506
1507 [RequiresUnreferencedCode("calls WriteReferencedElement")]
1509 {
1510 WriteReferencedElement(null, null, o, ambientType);
1511 }
1512
1513 [RequiresUnreferencedCode("calls WriteArray")]
1514 private void WriteReferencedElement(string name, string ns, object o, Type ambientType)
1515 {
1516 if (name == null)
1517 {
1518 name = string.Empty;
1519 }
1520 Type type = o.GetType();
1521 if (type.IsArray || typeof(IEnumerable).IsAssignableFrom(type))
1522 {
1523 WriteArray(name, ns, o, type);
1524 return;
1525 }
1527 if (typeEntry == null)
1528 {
1530 }
1531 WriteStartElement((name.Length == 0) ? typeEntry.typeName : name, (ns == null) ? typeEntry.typeNs : ns, null, writePrefixed: true);
1532 WriteId(o, addToReferencesList: false);
1533 if (ambientType != type)
1534 {
1535 WriteXsiType(typeEntry.typeName, typeEntry.typeNs);
1536 }
1537 typeEntry.callback(o);
1539 }
1540
1541 [RequiresUnreferencedCode("calls InitCallbacks")]
1543 {
1544 if (_typeEntries == null)
1545 {
1546 _typeEntries = new Hashtable();
1547 InitCallbacks();
1548 }
1549 return (TypeEntry)_typeEntries[t];
1550 }
1551
1552 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly")]
1553 protected abstract void InitCallbacks();
1554
1555 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly")]
1557 {
1558 if (_referencesToWrite != null)
1559 {
1560 for (int i = 0; i < _referencesToWrite.Count; i++)
1561 {
1563 }
1564 }
1565 }
1566
1567 protected void TopLevelElement()
1568 {
1569 _objectsInUse = new Hashtable();
1570 }
1571
1573 {
1574 if (xmlns != null)
1575 {
1576 foreach (XmlQualifiedName namespace2 in xmlns.Namespaces)
1577 {
1578 string name = namespace2.Name;
1579 string @namespace = namespace2.Namespace;
1580 if (_namespaces != null && _namespaces.TryLookupNamespace(name, out var ns) && ns != null && ns != @namespace)
1581 {
1582 throw new InvalidOperationException(System.SR.Format(System.SR.XmlDuplicateNs, name, @namespace));
1583 }
1584 string text = ((@namespace == null || @namespace.Length == 0) ? null : Writer.LookupPrefix(@namespace));
1585 if (text == null || text != name)
1586 {
1587 WriteAttribute("xmlns", name, null, @namespace);
1588 }
1589 }
1590 }
1591 _namespaces = null;
1592 }
1593
1594 private string NextPrefix()
1595 {
1596 if (_usedPrefixes == null)
1597 {
1598 string aliasBase = _aliasBase;
1599 int num = ++_tempNamespacePrefix;
1600 return aliasBase + num;
1601 }
1603 {
1604 }
1606 }
1607}
virtual int Add(object? value)
void Add(TKey key, TValue value)
virtual bool Contains(object key)
Definition Hashtable.cs:719
virtual bool ContainsKey(object key)
Definition Hashtable.cs:724
virtual void Remove(object key)
virtual void Add(object key, object? value)
Definition Hashtable.cs:676
static CultureInfo InvariantCulture
static string XmlNoAttributeHere
Definition SR.cs:1510
static string XmlUnxpectedType
Definition SR.cs:1586
static string XmlInvalidXmlns
Definition SR.cs:1610
static string XmlElementNameMismatch
Definition SR.cs:1514
static string XmlNeedAttributeHere
Definition SR.cs:1512
static string XmlChoiceIdentifierMismatch
Definition SR.cs:1704
static string XmlInvalidUseOfType
Definition SR.cs:1584
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string XmlDuplicateNs
Definition SR.cs:1744
static string XmlUnknownConstant
Definition SR.cs:1526
static string XmlIllegalAnyElement
Definition SR.cs:1472
static string XmlInvalidChoiceIdentifierValue
Definition SR.cs:1698
static string XmlUnknownAnyElement
Definition SR.cs:1588
static string XmlInvalidSerializable
Definition SR.cs:1582
static string XmlCircularReference
Definition SR.cs:1612
static string XmlChoiceMismatchChoiceException
Definition SR.cs:1658
Definition SR.cs:7
static TypeCode GetTypeCode(Type? type)
Definition Type.cs:919
static Assembly Get(string fullName)
static XmlQualifiedName ParseWsdlArrayType(string type, out string dims, XmlSchemaObject parent)
Definition TypeScope.cs:907
static Type GetArrayElementType(Type type, string memberInfo)
Definition TypeScope.cs:576
TypeDesc GetTypeDesc(string name, string ns)
Definition TypeScope.cs:224
static string FromEnum(long val, string[] vals, long[] ids, string typeName)
static string FromXmlNmTokens(string nmTokens)
static void WriteArrayBase64(XmlWriter writer, byte[] inData, int start, int count)
void WriteStartElement(string name, string? ns, bool writePrefixed)
void WriteElementQualifiedName(string localName, XmlQualifiedName? value, XmlQualifiedName? xsiType)
void WriteElement(XmlNode node, string name, string ns, bool isNullable, bool any)
void Init(XmlWriter w, XmlSerializerNamespaces namespaces, string encodingStyle, string idBase, TempAssembly tempAssembly)
void WriteElementQualifiedName(string localName, XmlQualifiedName? value)
void WriteNullableQualifiedNameEncoded(string name, string? ns, XmlQualifiedName? value, XmlQualifiedName? xsiType)
void WriteElementString(string localName, string? value, XmlQualifiedName? xsiType)
void WriteElementString(string localName, string? ns, string? value)
void WriteReferencingElement(string n, string? ns, object? o)
void WriteAttribute(string localName, string ns, byte[]? value)
void WriteElementStringRaw(string localName, string? ns, string? value)
void WritePotentiallyReferencingElement(string n, string? ns, object? o, Type? ambientType, bool suppressReference)
void WriteNullableStringLiteral(string name, string? ns, string? value)
void WriteXmlAttribute(XmlNode node, object? container)
void WriteElementStringRaw(string localName, string? ns, string? value, XmlQualifiedName? xsiType)
void WritePotentiallyReferencingElement(string? n, string? ns, object? o)
void WriteNamespaceDeclarations(XmlSerializerNamespaces? xmlns)
void WriteNullableStringEncoded(string name, string? ns, string? value, XmlQualifiedName? xsiType)
void WriteElementString(string localName, string? ns, string? value, XmlQualifiedName? xsiType)
void WriteElementString(string localName, string? value)
Exception CreateInvalidEnumValueException(object value, string typeName)
void WriteAttribute(string localName, byte[]? value)
void WriteTypedPrimitive(string? name, string? ns, object o, bool xsiType)
void WriteNullableStringLiteralRaw(string name, string? ns, byte[]? value)
void WriteNullableStringLiteralRaw(string name, string? ns, string? value)
void WriteStartElement(string name, string? ns, object? o, bool writePrefixed)
void WriteReferencingElement(string n, string? ns, object? o, bool isNullable)
void WriteAttribute(string? prefix, string localName, string? ns, string? value)
void WriteStartElement(string name, string? ns, object? o, bool writePrefixed, XmlSerializerNamespaces? xmlns)
void WriteReferencedElement(string name, string ns, object o, Type ambientType)
void WriteAttribute(string localName, string? value)
static string FromEnum(long value, string[] values, long[] ids)
void AddWriteCallback(Type type, string typeName, string? typeNs, XmlSerializationWriteCallback callback)
Exception CreateInvalidChoiceIdentifierValueException(string type, string identifier)
void WriteElementStringRaw(string localName, byte[]? value, XmlQualifiedName? xsiType)
static ? Assembly ResolveDynamicAssembly(string assemblyFullName)
void WriteNullableQualifiedNameLiteral(string name, string? ns, XmlQualifiedName? value)
void WriteId(object o, bool addToReferencesList)
void WriteElementStringRaw(string localName, string? value)
void WriteElementStringRaw(string localName, string? value, XmlQualifiedName? xsiType)
void WritePotentiallyReferencingElement(string? n, string? ns, object? o, Type? ambientType, bool suppressReference, bool isNullable)
void WriteElementStringRaw(string localName, byte[]? value)
static XmlQualifiedName GetPrimitiveTypeNameInternal(Type type)
XmlQualifiedName GetPrimitiveTypeName(Type type, bool throwIfUnknown)
void WritePotentiallyReferencingElement(string? n, string? ns, object? o, Type? ambientType)
Exception CreateMismatchChoiceException(string value, string elementName, string enumValue)
void WriteElementStringRaw(string localName, string? ns, byte[]? value, XmlQualifiedName? xsiType)
Exception CreateUnknownAnyElementException(string name, string ns)
void WriteNullableStringEncodedRaw(string name, string? ns, byte[]? value, XmlQualifiedName? xsiType)
void WriteNullableStringEncodedRaw(string name, string? ns, string? value, XmlQualifiedName? xsiType)
void WriteElementQualifiedName(string localName, string? ns, XmlQualifiedName? value)
string? FromXmlQualifiedName(XmlQualifiedName? xmlQualifiedName)
void WriteSerializable(IXmlSerializable? serializable, string name, string? ns, bool isNullable, bool wrapped)
HashSet< int > ListUsedPrefixes(XmlSerializerNamespaces nsList, string prefix)
Exception CreateChoiceIdentifierValueException(string value, string identifier, string name, string ns)
void WriteStartElement(string name, string? ns, object? o)
void WriteElementEncoded(XmlNode? node, string name, string? ns, bool isNullable, bool any)
string GetId(object o, bool addToReferencesList)
void WriteAttribute(string localName, string? ns, string? value)
void WriteElementQualifiedName(string localName, string? ns, XmlQualifiedName? value, XmlQualifiedName? xsiType)
void WriteElementStringRaw(string localName, string? ns, byte[]? value)
void WriteSerializable(IXmlSerializable? serializable, string name, string ns, bool isNullable)
string? FromXmlQualifiedName(XmlQualifiedName? xmlQualifiedName, bool ignoreEmpty)
void WriteElementLiteral(XmlNode? node, string name, string? ns, bool isNullable, bool any)
static string FromEnum(long value, string[] values, long[] ids, string typeName)
void WriteArray(string name, string ns, object o, Type type)
Dictionary< string, XmlQualifiedName >.ValueCollection Namespaces
static string ToString(bool value)
static ? string EncodeLocalName(string? name)
Definition XmlConvert.cs:49
void WriteString(string? text)
string? LookupPrefix(string ns)
void WriteElementString(string localName, string? value)
Definition XmlWriter.cs:412
void WriteRaw(char[] buffer, int index, int count)
WriteState WriteState
Definition XmlWriter.cs:16
void WriteStartAttribute(string localName, string? ns)
Definition XmlWriter.cs:67
void WriteAttributeString(string localName, string? ns, string? value)
Definition XmlWriter.cs:46
void WriteStartElement(string localName, string? ns)
Definition XmlWriter.cs:30
TypeCode
Definition TypeCode.cs:4