Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ReflectionXmlSerializationWriter.cs
Go to the documentation of this file.
5using System.Text;
7
9
11{
12 [Flags]
14 {
15 None = 0,
16 Raw = 1,
20 Encoded = 0x10
21 }
22
23 private readonly XmlMapping _mapping;
24
26 {
28 if (!xmlMapping.IsWriteable || !xmlMapping.GenerateSerializer)
29 {
30 throw new ArgumentException(System.SR.Format(System.SR.XmlInternalError, "xmlMapping"));
31 }
33 {
35 return;
36 }
37 throw new ArgumentException(System.SR.Format(System.SR.XmlInternalError, "xmlMapping"));
38 }
39
40 [RequiresUnreferencedCode("Members from serialized types may be trimmed if not referenced directly")]
41 protected override void InitCallbacks()
42 {
43 TypeScope scope = _mapping.Scope;
44 foreach (TypeMapping typeMapping in scope.TypeMappings)
45 {
46 if (typeMapping.IsSoap && (typeMapping is StructMapping || typeMapping is EnumMapping) && !typeMapping.TypeDesc.IsRoot)
47 {
48 AddWriteCallback(typeMapping.TypeDesc.Type, typeMapping.TypeName, typeMapping.Namespace, CreateXmlSerializationWriteCallback(typeMapping, typeMapping.TypeName, typeMapping.Namespace, typeMapping.TypeDesc.IsNullable));
49 }
50 }
51 }
52
53 [RequiresUnreferencedCode("calls WriteObjectOfTypeElement")]
66
67 [RequiresUnreferencedCode("calls GenerateTypeElement")]
72
73 [RequiresUnreferencedCode("calls WriteReferencedElements")]
75 {
79 if (o == null)
80 {
81 string ns = ((accessor.Form == XmlSchemaForm.Qualified) ? accessor.Namespace : string.Empty);
82 if (accessor.IsNullable)
83 {
84 if (mapping.IsSoap)
85 {
87 }
88 else
89 {
91 }
92 }
93 else
94 {
95 WriteEmptyTag(accessor.Name, ns);
96 }
97 return;
98 }
99 if (!mapping.TypeDesc.IsValueType && !mapping.TypeDesc.Type.IsPrimitive)
100 {
102 }
103 WriteMember(o, null, new ElementAccessor[1] { accessor }, null, null, mapping.TypeDesc, !accessor.IsSoap);
104 if (mapping.IsSoap)
105 {
107 }
108 }
109
110 [RequiresUnreferencedCode("calls WriteElements")]
112 {
113 if (memberTypeDesc.IsArrayLike && (elements.Length != 1 || !(elements[0].Mapping is ArrayMapping)))
114 {
116 }
117 else
118 {
120 }
121 }
122
123 [RequiresUnreferencedCode("calls WriteArrayItems")]
125 {
126 if ((elements.Length != 0 || text != null) && (!arrayTypeDesc.IsNullable || o != null))
127 {
128 if (choice != null && (choiceSource == null || ((Array)choiceSource).Length < ((Array)o).Length))
129 {
130 throw CreateInvalidChoiceIdentifierValueException(choice.Mapping.TypeDesc.FullName, choice.MemberName);
131 }
133 }
134 }
135
136 [RequiresUnreferencedCode("calls WriteElements")]
138 {
139 if (o is IList list)
140 {
141 for (int i = 0; i < list.Count; i++)
142 {
143 object o2 = list[i];
144 WriteElements(o2, null, elements, text, choice, writeAccessors: true, isNullable: true);
145 }
146 return;
147 }
148 IEnumerable enumerable = o as IEnumerable;
149 IEnumerator enumerator = enumerable.GetEnumerator();
150 if (enumerator != null)
151 {
152 while (enumerator.MoveNext())
153 {
154 object current = enumerator.Current;
155 WriteElements(current, null, elements, text, choice, writeAccessors: true, isNullable: true);
156 }
157 }
158 }
159
160 [RequiresUnreferencedCode("calls CreateUnknownTypeException")]
162 {
163 if (elements.Length == 0 && text == null)
164 {
165 return;
166 }
167 if (elements.Length == 1 && text == null)
168 {
169 WriteElement(o, elements[0], writeAccessors);
170 }
171 else
172 {
173 if (isNullable && choice == null && o == null)
174 {
175 return;
176 }
177 int num = 0;
180 foreach (ElementAccessor elementAccessor2 in elements)
181 {
182 if (elementAccessor2.Any)
183 {
184 num++;
185 if (elementAccessor2.Name != null && elementAccessor2.Name.Length > 0)
186 {
188 }
189 else if (elementAccessor == null)
190 {
192 }
193 }
194 else if (choice != null)
195 {
196 if (o != null && o.GetType() == elementAccessor2.Mapping.TypeDesc.Type)
197 {
199 return;
200 }
201 }
202 else
203 {
204 TypeDesc typeDesc = (elementAccessor2.IsUnbounded ? elementAccessor2.Mapping.TypeDesc.CreateArrayTypeDesc() : elementAccessor2.Mapping.TypeDesc);
205 if (o.GetType() == typeDesc.Type)
206 {
208 return;
209 }
210 }
211 }
212 if (num > 0 && o is XmlElement xmlElement)
213 {
214 foreach (ElementAccessor item in list)
215 {
216 if (item.Name == xmlElement.Name && item.Namespace == xmlElement.NamespaceURI)
217 {
219 return;
220 }
221 }
222 if (choice != null)
223 {
224 throw CreateChoiceIdentifierValueException(choice.Mapping.TypeDesc.FullName, choice.MemberName, xmlElement.Name, xmlElement.NamespaceURI);
225 }
226 if (elementAccessor == null)
227 {
229 }
231 }
232 else if (text != null)
233 {
234 WriteText(o, text);
235 }
236 else if (elements.Length != 0 && o != null)
237 {
239 }
240 }
241 }
242
243 private void WriteText(object o, TextAccessor text)
244 {
246 {
247 string stringValue;
248 if (text.Mapping is EnumMapping mapping)
249 {
251 }
252 else
253 {
255 }
256 if (o is byte[] value)
257 {
259 }
260 else
261 {
263 }
264 }
265 else if (text.Mapping is SpecialMapping specialMapping)
266 {
267 TypeKind kind = specialMapping.TypeDesc.Kind;
268 if (kind != TypeKind.Node)
269 {
271 }
272 ((XmlNode)o).WriteTo(base.Writer);
273 }
274 }
275
276 [RequiresUnreferencedCode("calls WritePotentiallyReferencingElement")]
277 private void WriteElement(object o, ElementAccessor element, bool writeAccessor)
278 {
279 string text = (writeAccessor ? element.Name : element.Mapping.TypeName);
280 string ns = ((element.Any && element.Name.Length == 0) ? null : ((element.Form != XmlSchemaForm.Qualified) ? string.Empty : (writeAccessor ? element.Namespace : element.Mapping.Namespace)));
282 {
283 if (o != null)
284 {
288 }
289 else if (element.IsNullable)
290 {
291 WriteNullTagLiteral(element.Name, ns);
292 }
293 return;
294 }
295 if (element.Mapping is ArrayMapping)
296 {
298 if (element.IsNullable && o == null)
299 {
300 WriteNullTagLiteral(element.Name, (element.Form == XmlSchemaForm.Qualified) ? element.Namespace : string.Empty);
301 return;
302 }
303 if (arrayMapping.IsSoap)
304 {
305 if (arrayMapping.Elements == null || arrayMapping.Elements.Length != 1)
306 {
308 }
309 if (!writeAccessor)
310 {
312 }
313 else
314 {
316 }
317 return;
318 }
319 if (element.IsUnbounded)
320 {
321 IEnumerable enumerable = (IEnumerable)o;
322 {
323 foreach (object item in enumerable)
324 {
325 element.IsUnbounded = false;
327 element.IsUnbounded = true;
328 }
329 return;
330 }
331 }
332 if (o != null)
333 {
335 WriteArrayItems(arrayMapping.ElementsSortedByDerivation, null, null, arrayMapping.TypeDesc, o);
337 }
338 return;
339 }
340 if (element.Mapping is EnumMapping)
341 {
342 if (element.Mapping.IsSoap)
343 {
344 base.Writer.WriteStartElement(text, ns);
347 }
348 else
349 {
350 WritePrimitive(WritePrimitiveMethodRequirement.WriteElementString, text, ns, element.Default, o, element.Mapping, writeXsiType: false, isElement: true, element.IsNullable);
351 }
352 return;
353 }
354 if (element.Mapping is PrimitiveMapping)
355 {
358 {
360 }
361 else if (o == null && element.IsNullable)
362 {
363 if (primitiveMapping.IsSoap)
364 {
365 WriteNullTagEncoded(element.Name, ns);
366 }
367 else
368 {
369 WriteNullTagLiteral(element.Name, ns);
370 }
371 }
372 else
373 {
377 }
378 return;
379 }
380 if (element.Mapping is StructMapping)
381 {
383 if (structMapping.IsSoap)
384 {
386 }
387 else
388 {
390 }
391 return;
392 }
393 if (element.Mapping is SpecialMapping)
394 {
395 if (element.Mapping is SerializableMapping)
396 {
397 WriteSerializable((IXmlSerializable)o, text, ns, element.IsNullable, !element.Any);
398 return;
399 }
400 if (o is XmlNode node)
401 {
402 WriteElementLiteral(node, text, ns, element.IsNullable, element.Any);
403 return;
404 }
406 }
408 }
409
410 [RequiresUnreferencedCode("calls WriteStructMethod")]
411 private XmlSerializationWriteCallback CreateXmlSerializationWriteCallback(TypeMapping mapping, string name, string ns, bool isNullable)
412 {
414 if (structMapping != null)
415 {
416 return Wrapper;
417 }
419 if (enumMapping != null)
420 {
421 return delegate(object o)
422 {
424 };
425 }
427 [RequiresUnreferencedCode("calls WriteStructMethod")]
428 void Wrapper(object o)
429 {
431 }
432 }
433
434 private void WriteQualifiedNameElement(string name, string ns, object defaultValue, XmlQualifiedName o, bool nullable, bool isSoap, PrimitiveMapping mapping)
435 {
436 if (defaultValue != null && defaultValue != DBNull.Value && mapping.TypeDesc.HasDefaultSupport && IsDefaultValue(mapping, o, defaultValue, nullable))
437 {
438 return;
439 }
440 if (isSoap)
441 {
442 if (nullable)
443 {
444 WriteNullableQualifiedNameEncoded(name, ns, o, new XmlQualifiedName(mapping.TypeName, mapping.Namespace));
445 }
446 else
447 {
448 WriteElementQualifiedName(name, ns, o, new XmlQualifiedName(mapping.TypeName, mapping.Namespace));
449 }
450 }
451 else if (nullable)
452 {
454 }
455 else
456 {
457 WriteElementQualifiedName(name, ns, o);
458 }
459 }
460
461 [RequiresUnreferencedCode("calls WriteTypedPrimitive")]
462 private void WriteStructMethod(StructMapping mapping, string n, string ns, object o, bool isNullable, bool needType)
463 {
464 if (mapping.IsSoap && mapping.TypeDesc.IsRoot)
465 {
466 return;
467 }
468 if (!mapping.IsSoap)
469 {
470 if (o == null)
471 {
472 if (isNullable)
473 {
475 }
476 return;
477 }
478 if (!needType && o.GetType() != mapping.TypeDesc.Type)
479 {
481 {
482 if (!mapping.TypeDesc.IsRoot)
483 {
485 }
486 if (!WriteEnumAndArrayTypes(mapping, o, n, ns))
487 {
488 WriteTypedPrimitive(n, ns, o, xsiType: true);
489 }
490 }
491 return;
492 }
493 }
494 if (mapping.TypeDesc.IsAbstract)
495 {
496 return;
497 }
498 if (mapping.TypeDesc.Type != null && typeof(XmlSchemaObject).IsAssignableFrom(mapping.TypeDesc.Type))
499 {
500 base.EscapeName = false;
501 }
504 int num = FindXmlnsIndex(allMembers);
505 if (num >= 0)
506 {
509 }
510 if (!mapping.IsSoap)
511 {
513 if (!mapping.TypeDesc.IsRoot && needType)
514 {
515 WriteXsiType(mapping.TypeName, mapping.Namespace);
516 }
517 }
518 else if (xmlSerializerNamespaces != null)
519 {
521 }
523 {
524 bool flag = true;
525 bool flag2 = true;
526 if (memberMapping2.CheckSpecified != 0)
527 {
528 string memberName = memberMapping2.Name + "Specified";
530 }
531 if (memberMapping2.CheckShouldPersist)
532 {
533 string name = "ShouldSerialize" + memberMapping2.Name;
534 MethodInfo method = o.GetType().GetMethod(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
535 flag2 = (bool)method.Invoke(o, Array.Empty<object>());
536 }
537 if (memberMapping2.Attribute != null && flag && flag2)
538 {
541 }
542 }
544 {
545 if (memberMapping3.Xmlns != null)
546 {
547 continue;
548 }
549 bool flag3 = true;
550 bool flag4 = true;
551 if (memberMapping3.CheckSpecified != 0)
552 {
553 string memberName2 = memberMapping3.Name + "Specified";
555 }
556 if (memberMapping3.CheckShouldPersist)
557 {
558 string name2 = "ShouldSerialize" + memberMapping3.Name;
559 MethodInfo method2 = o.GetType().GetMethod(name2, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
560 flag4 = (bool)method2.Invoke(o, Array.Empty<object>());
561 }
562 if (!memberMapping3.CheckShouldPersist || (memberMapping3.Elements.Length == 0 && memberMapping3.Text == null))
563 {
564 flag4 = true;
565 }
566 if (flag3 && flag4)
567 {
568 object choiceSource = null;
569 if (memberMapping3.ChoiceIdentifier != null)
570 {
571 choiceSource = GetMemberValue(o, memberMapping3.ChoiceIdentifier.MemberName);
572 }
574 WriteMember(memberValue2, choiceSource, memberMapping3.ElementsSortedByDerivation, memberMapping3.Text, memberMapping3.ChoiceIdentifier, memberMapping3.TypeDesc, writeAccessors: true);
575 }
576 }
577 if (!mapping.IsSoap)
578 {
580 }
581 }
582
583 [RequiresUnreferencedCode("Calls GetType on object")]
589
590 [RequiresUnreferencedCode("calls WriteMember")]
591 private bool WriteEnumAndArrayTypes(StructMapping structMapping, object o, string n, string ns)
592 {
593 Type type = o.GetType();
594 foreach (object typeMapping in _mapping.Scope.TypeMappings)
595 {
596 if (typeMapping is EnumMapping enumMapping && enumMapping.TypeDesc.Type == type)
597 {
598 base.Writer.WriteStartElement(n, ns);
599 WriteXsiType(enumMapping.TypeName, ns);
600 base.Writer.WriteString(WriteEnumMethod(enumMapping, o));
601 base.Writer.WriteEndElement();
602 return true;
603 }
605 {
606 base.Writer.WriteStartElement(n, ns);
607 WriteXsiType(arrayMapping.TypeName, ns);
608 WriteMember(o, null, arrayMapping.ElementsSortedByDerivation, null, null, arrayMapping.TypeDesc, writeAccessors: true);
609 base.Writer.WriteEndElement();
610 return true;
611 }
612 }
613 return false;
614 }
615
616 private string WriteEnumMethod(EnumMapping mapping, object v)
617 {
618 string text = null;
619 if (mapping != null)
620 {
621 ConstantMapping[] constants = mapping.Constants;
622 if (constants.Length != 0)
623 {
624 bool flag = false;
625 long num = Convert.ToInt64(v);
627 {
628 if (num == constantMapping.Value)
629 {
630 text = constantMapping.XmlName;
631 flag = true;
632 break;
633 }
634 }
635 if (!flag)
636 {
637 if (!mapping.IsFlags)
638 {
639 throw CreateInvalidEnumValueException(v, mapping.TypeDesc.FullName);
640 }
641 string[] array = new string[constants.Length];
642 long[] array2 = new long[constants.Length];
643 for (int j = 0; j < constants.Length; j++)
644 {
645 array[j] = constants[j].XmlName;
646 array2[j] = constants[j].Value;
647 }
649 }
650 }
651 }
652 else
653 {
654 text = v.ToString();
655 }
656 if (mapping.IsSoap)
657 {
658 WriteXsiType(mapping.TypeName, mapping.Namespace);
659 base.Writer.WriteString(text);
660 return null;
661 }
662 return text;
663 }
664
665 private object GetMemberValue(object o, MemberInfo memberInfo)
666 {
667 if (memberInfo is PropertyInfo propertyInfo)
668 {
669 return propertyInfo.GetValue(o);
670 }
672 {
673 return fieldInfo.GetValue(o);
674 }
676 }
677
679 {
680 if (memberTypeDesc.IsAbstract)
681 {
682 return;
683 }
684 if (memberTypeDesc.IsArrayLike)
685 {
687 TypeDesc arrayElementTypeDesc = memberTypeDesc.ArrayElementTypeDesc;
689 if (attribute.IsList && flag)
690 {
691 base.Writer.WriteStartAttribute(null, attribute.Name, (attribute.Form == XmlSchemaForm.Qualified) ? attribute.Namespace : string.Empty);
692 }
693 if (memberValue == null)
694 {
695 return;
696 }
697 IEnumerable enumerable = (IEnumerable)memberValue;
698 IEnumerator enumerator = enumerable.GetEnumerator();
699 bool flag2 = false;
700 if (enumerator == null)
701 {
702 return;
703 }
704 while (enumerator.MoveNext())
705 {
706 object current = enumerator.Current;
707 if (attribute.IsList)
708 {
709 string stringValue;
710 if (attribute.Mapping is EnumMapping mapping)
711 {
713 }
714 else
715 {
717 }
718 if (flag)
719 {
720 if (flag2)
721 {
722 base.Writer.WriteString(" ");
723 }
724 if (current is byte[])
725 {
726 WriteValue((byte[])current);
727 }
728 else
729 {
731 }
732 }
733 else
734 {
735 if (flag2)
736 {
737 stringBuilder.Append(' ');
738 }
740 }
741 }
742 else
743 {
744 WriteAttribute(current, attribute, container);
745 }
746 flag2 = true;
747 }
748 if (attribute.IsList)
749 {
750 if (flag)
751 {
752 base.Writer.WriteEndAttribute();
753 }
754 else if (stringBuilder.Length != 0)
755 {
756 string ns = ((attribute.Form == XmlSchemaForm.Qualified) ? attribute.Namespace : string.Empty);
757 WriteAttribute(attribute.Name, ns, stringBuilder.ToString());
758 }
759 }
760 }
761 else
762 {
764 }
765 }
766
768 {
769 if (listElementTypeDesc != null)
770 {
772 }
773 return false;
774 }
775
776 private void WriteAttribute(object memberValue, AttributeAccessor attribute, object container)
777 {
779 {
780 if (specialMapping.TypeDesc.Kind != TypeKind.Attribute && !specialMapping.TypeDesc.CanBeAttributeValue)
781 {
783 }
785 }
786 else
787 {
788 string ns = ((attribute.Form == XmlSchemaForm.Qualified) ? attribute.Namespace : string.Empty);
789 WritePrimitive(WritePrimitiveMethodRequirement.WriteAttribute, attribute.Name, ns, attribute.Default, memberValue, attribute.Mapping, writeXsiType: false, isElement: false, isNullable: false);
790 }
791 }
792
794 {
795 for (int i = 0; i < members.Length; i++)
796 {
797 if (members[i].Xmlns != null)
798 {
799 return i;
800 }
801 }
802 return -1;
803 }
804
805 [RequiresUnreferencedCode("calls WriteStructMethod")]
806 private bool WriteDerivedTypes(StructMapping mapping, string n, string ns, object o, bool isNullable)
807 {
808 Type type = o.GetType();
809 for (StructMapping structMapping = mapping.DerivedMappings; structMapping != null; structMapping = structMapping.NextDerivedMapping)
810 {
811 if (type == structMapping.TypeDesc.Type)
812 {
814 return true;
815 }
817 {
818 return true;
819 }
820 }
821 return false;
822 }
823
824 private void WritePrimitive(WritePrimitiveMethodRequirement method, string name, string ns, object defaultValue, object o, TypeMapping mapping, bool writeXsiType, bool isElement, bool isNullable)
825 {
826 TypeDesc typeDesc = mapping.TypeDesc;
827 if (defaultValue != null && defaultValue != DBNull.Value && mapping.TypeDesc.HasDefaultSupport)
828 {
830 {
831 if (((EnumMapping)mapping).IsFlags)
832 {
833 IEnumerable<string> values = defaultValue.ToString().Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
834 string text = string.Join(", ", values);
835 if (o.ToString() == text)
836 {
837 return;
838 }
839 }
840 else if (o.ToString() == defaultValue.ToString())
841 {
842 return;
843 }
844 }
846 {
847 return;
848 }
849 }
851 if (writeXsiType)
852 {
853 xsiType = new XmlQualifiedName(mapping.TypeName, mapping.Namespace);
854 }
855 string stringValue = null;
856 bool flag = false;
858 {
860 flag = true;
861 }
862 else
863 {
865 }
866 if (flag)
867 {
869 {
871 {
873 }
874 else
875 {
877 }
878 }
879 else if (hasRequirement(method, WritePrimitiveMethodRequirement.WriteNullableStringLiteral))
880 {
882 {
884 {
886 }
887 else
888 {
890 }
891 }
893 {
895 }
896 else
897 {
899 }
900 }
901 else if (hasRequirement(method, WritePrimitiveMethodRequirement.WriteAttribute))
902 {
903 WriteAttribute(name, ns, stringValue);
904 }
905 }
906 else if (o is byte[] value)
907 {
909 {
911 }
913 {
915 }
916 else if (hasRequirement(method, WritePrimitiveMethodRequirement.WriteAttribute))
917 {
918 WriteAttribute(name, ns, value);
919 }
920 }
921 }
922
927
928 private bool IsDefaultValue(TypeMapping mapping, object o, object value, bool isNullable)
929 {
930 if (value is string && ((string)value).Length == 0)
931 {
932 string text = (string)o;
933 if (text != null)
934 {
935 return text.Length == 0;
936 }
937 return true;
938 }
939 return value.Equals(o);
940 }
941
942 private bool WritePrimitiveValue(TypeDesc typeDesc, object o, bool isElement, out string stringValue)
943 {
944 if (typeDesc == ReflectionXmlSerializationReader.StringTypeDesc || typeDesc.FormatterName == "String")
945 {
947 return true;
948 }
949 if (!typeDesc.HasCustomFormatter)
950 {
952 return true;
953 }
954 if (o is byte[] && typeDesc.FormatterName == "ByteArrayHex")
955 {
957 return true;
958 }
959 if (o is DateTime)
960 {
961 if (typeDesc.FormatterName == "DateTime")
962 {
964 return true;
965 }
966 if (typeDesc.FormatterName == "Date")
967 {
969 return true;
970 }
971 if (typeDesc.FormatterName == "Time")
972 {
974 return true;
975 }
977 }
979 {
981 return true;
982 }
983 if (o is string)
984 {
985 switch (typeDesc.FormatterName)
986 {
987 case "XmlName":
989 break;
990 case "XmlNCName":
992 break;
993 case "XmlNmToken":
995 break;
996 case "XmlNmTokens":
998 break;
999 default:
1000 stringValue = null;
1001 return false;
1002 }
1003 return true;
1004 }
1005 if (o is char && typeDesc.FormatterName == "Char")
1006 {
1008 return true;
1009 }
1010 if (!(o is byte[]))
1011 {
1013 }
1014 stringValue = null;
1015 return false;
1016 }
1017
1019 {
1020 return typeDesc.FormatterName switch
1021 {
1022 "Boolean" => XmlConvert.ToString((bool)o),
1023 "Int32" => XmlConvert.ToString((int)o),
1024 "Int16" => XmlConvert.ToString((short)o),
1025 "Int64" => XmlConvert.ToString((long)o),
1026 "Single" => XmlConvert.ToString((float)o),
1027 "Double" => XmlConvert.ToString((double)o),
1028 "Decimal" => XmlConvert.ToString((decimal)o),
1029 "Byte" => XmlConvert.ToString((byte)o),
1030 "SByte" => XmlConvert.ToString((sbyte)o),
1031 "UInt16" => XmlConvert.ToString((ushort)o),
1032 "UInt32" => XmlConvert.ToString((uint)o),
1033 "UInt64" => XmlConvert.ToString((ulong)o),
1034 "Guid" => XmlConvert.ToString((Guid)o),
1035 "Char" => XmlConvert.ToString((char)o),
1036 "TimeSpan" => XmlConvert.ToString((TimeSpan)o),
1037 "DateTimeOffset" => XmlConvert.ToString((DateTimeOffset)o),
1038 _ => o.ToString(),
1039 };
1040 }
1041
1042 [RequiresUnreferencedCode("calls WritePotentiallyReferencingElement")]
1044 {
1047 bool hasWrapperElement = membersMapping.HasWrapperElement;
1048 bool writeAccessors = membersMapping.WriteAccessors;
1051 if (!membersMapping.IsSoap)
1052 {
1054 }
1055 object[] array = (object[])o;
1056 int num = array.Length;
1058 {
1059 WriteStartElement(accessor.Name, (accessor.Form == XmlSchemaForm.Qualified) ? accessor.Namespace : string.Empty, membersMapping.IsSoap);
1060 int num2 = FindXmlnsIndex(membersMapping.Members);
1061 if (num2 >= 0)
1062 {
1064 if (num > num2)
1065 {
1067 }
1068 }
1069 for (int i = 0; i < membersMapping.Members.Length; i++)
1070 {
1072 if (memberMapping.Attribute == null || memberMapping.Ignore)
1073 {
1074 continue;
1075 }
1076 object memberValue = array[i];
1077 bool? flag2 = null;
1078 if (memberMapping.CheckSpecified != 0)
1079 {
1080 string text = memberMapping.Name + "Specified";
1081 for (int j = 0; j < Math.Min(num, membersMapping.Members.Length); j++)
1082 {
1083 if (membersMapping.Members[j].Name == text)
1084 {
1085 flag2 = (bool)array[j];
1086 break;
1087 }
1088 }
1089 }
1090 if (num > i && (!flag2.HasValue || flag2.Value))
1091 {
1092 WriteMember(memberValue, memberMapping.Attribute, memberMapping.TypeDesc, null);
1093 }
1094 }
1095 }
1096 for (int k = 0; k < membersMapping.Members.Length; k++)
1097 {
1099 if (memberMapping2.Xmlns != null || memberMapping2.Ignore)
1100 {
1101 continue;
1102 }
1103 bool? flag3 = null;
1104 if (memberMapping2.CheckSpecified != 0)
1105 {
1106 string text2 = memberMapping2.Name + "Specified";
1107 for (int l = 0; l < Math.Min(num, membersMapping.Members.Length); l++)
1108 {
1109 if (membersMapping.Members[l].Name == text2)
1110 {
1111 flag3 = (bool)array[l];
1112 break;
1113 }
1114 }
1115 }
1116 if (num <= k || (flag3.HasValue && !flag3.Value))
1117 {
1118 continue;
1119 }
1120 object o2 = array[k];
1121 object choiceSource = null;
1122 if (memberMapping2.ChoiceIdentifier != null)
1123 {
1124 for (int m = 0; m < membersMapping.Members.Length; m++)
1125 {
1126 if (membersMapping.Members[m].Name == memberMapping2.ChoiceIdentifier.MemberName)
1127 {
1128 choiceSource = array[m];
1129 break;
1130 }
1131 }
1132 }
1133 if (flag && memberMapping2.IsReturnValue && memberMapping2.Elements.Length != 0)
1134 {
1135 WriteRpcResult(memberMapping2.Elements[0].Name, string.Empty);
1136 }
1137 WriteMember(o2, choiceSource, memberMapping2.ElementsSortedByDerivation, memberMapping2.Text, memberMapping2.ChoiceIdentifier, memberMapping2.TypeDesc, writeAccessors || hasWrapperElement);
1138 }
1140 {
1142 }
1143 if (!accessor.IsSoap)
1144 {
1145 return;
1146 }
1147 if (!hasWrapperElement && !writeAccessors && num > membersMapping.Members.Length)
1148 {
1149 for (int n = membersMapping.Members.Length; n < num; n++)
1150 {
1151 if (array[n] != null)
1152 {
1153 WritePotentiallyReferencingElement(null, null, array[n], array[n].GetType(), suppressReference: true, isNullable: false);
1154 }
1155 }
1156 }
1158 }
1159}
void Add(TKey key, TValue value)
static long ToInt64(object? value)
Definition Convert.cs:1623
static readonly DBNull Value
Definition DBNull.cs:8
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static string XmlInternalError
Definition SR.cs:1812
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string XmlInternalErrorDetails
Definition SR.cs:1814
Definition SR.cs:7
static MemberInfo GetEffectiveGetInfo(Type declaringType, string memberName)
void WriteArrayItems(ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc, object o)
bool WritePrimitiveValue(TypeDesc typeDesc, object o, bool isElement, out string stringValue)
ReflectionXmlSerializationWriter(XmlMapping xmlMapping, XmlWriter xmlWriter, XmlSerializerNamespaces namespaces, string encodingStyle, string id)
void WriteArray(object o, object choiceSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc)
void GenerateMembersElement(object o, XmlMembersMapping xmlMembersMapping)
bool hasRequirement(WritePrimitiveMethodRequirement value, WritePrimitiveMethodRequirement requirement)
void WriteStructMethod(StructMapping mapping, string n, string ns, object o, bool isNullable, bool needType)
void WritePrimitive(WritePrimitiveMethodRequirement method, string name, string ns, object defaultValue, object o, TypeMapping mapping, bool writeXsiType, bool isElement, bool isNullable)
void WriteElement(object o, ElementAccessor element, bool writeAccessor)
void WriteAttribute(object memberValue, AttributeAccessor attribute, object container)
void WriteQualifiedNameElement(string name, string ns, object defaultValue, XmlQualifiedName o, bool nullable, bool isSoap, PrimitiveMapping mapping)
bool WriteEnumAndArrayTypes(StructMapping structMapping, object o, string n, string ns)
XmlSerializationWriteCallback CreateXmlSerializationWriteCallback(TypeMapping mapping, string name, string ns, bool isNullable)
void WriteMember(object memberValue, AttributeAccessor attribute, TypeDesc memberTypeDesc, object container)
bool IsDefaultValue(TypeMapping mapping, object o, object value, bool isNullable)
bool WriteDerivedTypes(StructMapping mapping, string n, string ns, object o, bool isNullable)
void WriteMember(object o, object choiceSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc memberTypeDesc, bool writeAccessors)
void WriteElements(object o, object enumSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, bool writeAccessors, bool isNullable)
static MemberMapping[] GetAllMembers(StructMapping mapping)
Definition TypeScope.cs:598
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 WritePotentiallyReferencingElement(string? n, string? ns, object? o)
void WriteNamespaceDeclarations(XmlSerializerNamespaces? xmlns)
void WriteNullableStringEncoded(string name, string? ns, string? value, XmlQualifiedName? xsiType)
Exception CreateInvalidEnumValueException(object value, string typeName)
void WriteTypedPrimitive(string? name, string? ns, object o, bool xsiType)
void WriteNullableStringLiteralRaw(string name, string? ns, 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 WriteNullableQualifiedNameLiteral(string name, string? ns, XmlQualifiedName? value)
void WriteElementStringRaw(string localName, string? value)
Exception CreateUnknownAnyElementException(string name, string ns)
void WriteNullableStringEncodedRaw(string name, string? ns, string? value, XmlQualifiedName? xsiType)
string? FromXmlQualifiedName(XmlQualifiedName? xmlQualifiedName)
Exception CreateChoiceIdentifierValueException(string value, string identifier, string name, string ns)
void WriteSerializable(IXmlSerializable? serializable, string name, string ns, bool isNullable)
void WriteElementLiteral(XmlNode? node, string name, string? ns, bool isNullable, bool any)
static string ToString(bool value)