Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlSerializationWriterILGen.cs
Go to the documentation of this file.
8using System.Text;
10
12
14{
15 [RequiresUnreferencedCode("creates XmlSerializationILGen")]
16 internal XmlSerializationWriterILGen(TypeScope[] scopes, string access, string className)
17 : base(scopes, access, className)
18 {
19 }
20
21 [RequiresUnreferencedCode("calls WriteReflectionInit")]
22 internal void GenerateBegin()
23 {
24 typeBuilder = CodeGenerator.CreateTypeBuilder(base.ModuleBuilder, base.ClassName, base.TypeAttributes | TypeAttributes.BeforeFieldInit, typeof(XmlSerializationWriter), Type.EmptyTypes);
25 TypeScope[] scopes = base.Scopes;
26 foreach (TypeScope typeScope in scopes)
27 {
28 foreach (TypeMapping typeMapping in typeScope.TypeMappings)
29 {
31 {
32 base.MethodNames.Add(typeMapping, NextMethodName(typeMapping.TypeDesc.Name));
33 }
34 }
35 base.RaCodeGen.WriteReflectionInit(typeScope);
36 }
37 }
38
39 [RequiresUnreferencedCode("calls WriteStructMethod")]
40 internal override void GenerateMethod(TypeMapping mapping)
41 {
42 if (base.GeneratedMethods.Add(mapping))
43 {
45 {
47 }
48 else if (mapping is EnumMapping)
49 {
51 }
52 }
53 }
54
55 [RequiresUnreferencedCode("calls GenerateReferencedMethods")]
63
64 [RequiresUnreferencedCode("calls GenerateTypeElement")]
66 {
67 if (!xmlMapping.IsWriteable)
68 {
69 return null;
70 }
71 if (!xmlMapping.GenerateSerializer)
72 {
73 throw new ArgumentException(System.SR.XmlInternalError, "xmlMapping");
74 }
76 {
78 }
80 {
82 }
83 throw new ArgumentException(System.SR.XmlInternalError, "xmlMapping");
84 }
85
87 {
89 ilg.BeginMethod(typeof(void), "InitCallbacks", Type.EmptyTypes, Array.Empty<string>(), MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.HideBySig);
90 ilg.EndMethod();
91 }
92
93 [RequiresUnreferencedCode("calls Load")]
94 private void WriteQualifiedNameElement(string name, string ns, object defaultValue, SourceInfo source, bool nullable, TypeMapping mapping)
95 {
96 bool flag = defaultValue != null && defaultValue != DBNull.Value;
97 if (flag)
98 {
99 throw Globals.NotSupported("XmlQualifiedName DefaultValue not supported. Fail in WriteValue()");
100 }
101 List<Type> list = new List<Type>();
102 ilg.Ldarg(0);
104 list.Add(typeof(string));
105 if (ns != null)
106 {
108 list.Add(typeof(string));
109 }
110 source.Load(mapping.TypeDesc.Type);
111 list.Add(mapping.TypeDesc.Type);
112 MethodInfo method = typeof(XmlSerializationWriter).GetMethod(nullable ? "WriteNullableQualifiedNameLiteral" : "WriteElementQualifiedName", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, list.ToArray());
113 ilg.Call(method);
114 if (flag)
115 {
116 throw Globals.NotSupported("XmlQualifiedName DefaultValue not supported. Fail in WriteValue()");
117 }
118 }
119
120 [RequiresUnreferencedCode("calls Load")]
130
131 [RequiresUnreferencedCode("calls Load")]
133 {
134 if (typeDesc == base.StringTypeDesc || typeDesc.FormatterName == "String")
135 {
136 source.Load(typeDesc.Type);
137 returnType = typeDesc.Type;
138 }
139 else if (!typeDesc.HasCustomFormatter)
140 {
141 Type type = typeDesc.Type;
142 if (type == typeof(byte))
143 {
144 type = typeof(short);
145 }
146 else if (type == typeof(ushort))
147 {
148 type = typeof(int);
149 }
150 MethodInfo method = typeof(XmlConvert).GetMethod("ToString", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { type });
151 source.Load(typeDesc.Type);
152 ilg.Call(method);
153 returnType = method.ReturnType;
154 }
155 else
156 {
158 if (typeDesc.FormatterName == "XmlQualifiedName")
159 {
161 ilg.Ldarg(0);
162 }
163 MethodInfo method2 = typeof(XmlSerializationWriter).GetMethod("From" + typeDesc.FormatterName, bindingAttr, new Type[1] { typeDesc.Type });
164 source.Load(typeDesc.Type);
166 returnType = method2.ReturnType;
167 }
168 }
169
170 [RequiresUnreferencedCode("Calls WriteCheckDefault")]
171 private void WritePrimitive(string method, string name, string ns, object defaultValue, SourceInfo source, TypeMapping mapping, bool writeXsiType, bool isElement, bool isNullable)
172 {
173 TypeDesc typeDesc = mapping.TypeDesc;
174 bool flag = defaultValue != null && defaultValue != DBNull.Value && mapping.TypeDesc.HasDefaultSupport;
175 if (flag)
176 {
178 {
179 source.Load(mapping.TypeDesc.Type);
180 string text = null;
181 if (((EnumMapping)mapping).IsFlags)
182 {
183 string[] array = ((string)defaultValue).Split((char[]?)null);
184 for (int i = 0; i < array.Length; i++)
185 {
186 if (array[i] != null && array[i].Length != 0)
187 {
188 if (i > 0)
189 {
190 text += ", ";
191 }
192 text += array[i];
193 }
194 }
195 }
196 else
197 {
199 }
200 ilg.Ldc(Enum.Parse(mapping.TypeDesc.Type, text, ignoreCase: false));
201 ilg.If(Cmp.NotEqualTo);
202 }
203 else
204 {
206 }
207 }
208 List<Type> list = new List<Type>();
209 ilg.Ldarg(0);
210 list.Add(typeof(string));
212 if (ns != null)
213 {
214 list.Add(typeof(string));
216 }
219 {
221 list.Add(returnType);
222 }
223 else
224 {
226 list.Add(returnType);
227 }
228 if (writeXsiType)
229 {
231 ConstructorInfo constructor = typeof(XmlQualifiedName).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[2]
232 {
233 typeof(string),
234 typeof(string)
235 });
236 ilg.Ldstr(GetCSharpString(mapping.TypeName));
237 ilg.Ldstr(GetCSharpString(mapping.Namespace));
239 }
240 MethodInfo method2 = typeof(XmlSerializationWriter).GetMethod(method, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, list.ToArray());
242 if (flag)
243 {
244 ilg.EndIf();
245 }
246 }
247
248 [RequiresUnreferencedCode("XmlSerializationWriter methods have RequiresUnreferencedCode")]
249 private void WriteTag(string methodName, string name, string ns)
250 {
251 MethodInfo method = typeof(XmlSerializationWriter).GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[2]
252 {
253 typeof(string),
254 typeof(string)
255 });
256 ilg.Ldarg(0);
259 ilg.Call(method);
260 }
261
262 [RequiresUnreferencedCode("XmlSerializationWriter methods have RequiresUnreferencedCode")]
263 private void WriteTag(string methodName, string name, string ns, bool writePrefixed)
264 {
265 MethodInfo method = typeof(XmlSerializationWriter).GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[4]
266 {
267 typeof(string),
268 typeof(string),
269 typeof(object),
270 typeof(bool)
271 });
272 ilg.Ldarg(0);
275 ilg.Load(null);
277 ilg.Call(method);
278 }
279
280 [RequiresUnreferencedCode("calls WriteTag")]
281 private void WriteStartElement(string name, string ns, bool writePrefixed)
282 {
283 WriteTag("WriteStartElement", name, ns, writePrefixed);
284 }
285
286 private void WriteEndElement()
287 {
288 MethodInfo method = typeof(XmlSerializationWriter).GetMethod("WriteEndElement", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
289 ilg.Ldarg(0);
290 ilg.Call(method);
291 }
292
293 private void WriteEndElement(string source)
294 {
295 MethodInfo method = typeof(XmlSerializationWriter).GetMethod("WriteEndElement", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { typeof(object) });
296 object variable = ilg.GetVariable(source);
297 ilg.Ldarg(0);
300 ilg.Call(method);
301 }
302
303 [RequiresUnreferencedCode("calls WriteTag")]
304 private void WriteLiteralNullTag(string name, string ns)
305 {
306 WriteTag("WriteNullTagLiteral", name, ns);
307 }
308
309 [RequiresUnreferencedCode("calls WriteTag")]
310 private void WriteEmptyTag(string name, string ns)
311 {
312 WriteTag("WriteEmptyTag", name, ns);
313 }
314
315 [RequiresUnreferencedCode("calls WriteMember")]
317 {
320 bool hasWrapperElement = membersMapping.HasWrapperElement;
321 bool writeAccessors = membersMapping.WriteAccessors;
322 string text = NextMethodName(accessor.Name);
324 ilg.BeginMethod(typeof(void), text, new Type[1] { typeof(object[]) }, new string[1] { "p" }, MethodAttributes.Public | MethodAttributes.HideBySig);
325 MethodInfo method = typeof(XmlSerializationWriter).GetMethod("WriteStartDocument", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
326 ilg.Ldarg(0);
327 ilg.Call(method);
328 MethodInfo method2 = typeof(XmlSerializationWriter).GetMethod("TopLevelElement", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
329 ilg.Ldarg(0);
332 ilg.Ldarg("p");
333 ilg.Ldlen();
336 {
337 WriteStartElement(accessor.Name, (accessor.Form == XmlSchemaForm.Qualified) ? accessor.Namespace : "", writePrefixed: false);
338 int num = FindXmlnsIndex(membersMapping.Members);
339 if (num >= 0)
340 {
343 handler.AppendLiteral("((");
345 handler.AppendLiteral(")p[");
346 handler.AppendFormatted(num);
347 handler.AppendLiteral("])");
348 string source = string.Create(invariantCulture, ref handler);
350 ilg.Ldc(num);
351 ilg.If(Cmp.GreaterThan);
353 ilg.EndIf();
354 }
355 for (int i = 0; i < membersMapping.Members.Length; i++)
356 {
358 if (memberMapping.Attribute == null || memberMapping.Ignore)
359 {
360 continue;
361 }
362 SourceInfo source2 = new SourceInfo($"p[{i}]", null, null, localBuilder.LocalType.GetElementType(), ilg);
363 SourceInfo sourceInfo = null;
364 int intVar = 0;
365 if (memberMapping.CheckSpecified != 0)
366 {
367 string text2 = memberMapping.Name + "Specified";
368 for (int j = 0; j < membersMapping.Members.Length; j++)
369 {
370 if (membersMapping.Members[j].Name == text2)
371 {
372 sourceInfo = new SourceInfo($"((bool)p[{j}])", null, null, typeof(bool), ilg);
373 intVar = j;
374 break;
375 }
376 }
377 }
379 ilg.Ldc(i);
380 ilg.If(Cmp.GreaterThan);
381 if (sourceInfo != null)
382 {
386 ilg.Ldc(intVar);
387 ilg.Ble(label);
388 sourceInfo.Load(typeof(bool));
389 ilg.Br_S(label2);
391 ilg.Ldc(boolVar: true);
393 ilg.If();
394 }
395 WriteMember(source2, memberMapping.Attribute, memberMapping.TypeDesc, "p");
396 if (sourceInfo != null)
397 {
398 ilg.EndIf();
399 }
400 ilg.EndIf();
401 }
402 }
403 for (int k = 0; k < membersMapping.Members.Length; k++)
404 {
406 if (memberMapping2.Xmlns != null || memberMapping2.Ignore)
407 {
408 continue;
409 }
410 SourceInfo sourceInfo2 = null;
411 int intVar2 = 0;
412 if (memberMapping2.CheckSpecified != 0)
413 {
414 string text3 = memberMapping2.Name + "Specified";
415 for (int l = 0; l < membersMapping.Members.Length; l++)
416 {
417 if (membersMapping.Members[l].Name == text3)
418 {
419 sourceInfo2 = new SourceInfo($"((bool)p[{l}])", null, null, typeof(bool), ilg);
420 intVar2 = l;
421 break;
422 }
423 }
424 }
426 ilg.Ldc(k);
427 ilg.If(Cmp.GreaterThan);
428 if (sourceInfo2 != null)
429 {
433 ilg.Ldc(intVar2);
434 ilg.Ble(label3);
435 sourceInfo2.Load(typeof(bool));
436 ilg.Br_S(label4);
438 ilg.Ldc(boolVar: true);
440 ilg.If();
441 }
442 string text4 = $"p[{k}]";
443 string choiceSource = null;
444 if (memberMapping2.ChoiceIdentifier != null)
445 {
446 for (int m = 0; m < membersMapping.Members.Length; m++)
447 {
448 if (membersMapping.Members[m].Name == memberMapping2.ChoiceIdentifier.MemberName)
449 {
450 choiceSource = $"(({membersMapping.Members[m].TypeDesc.CSharpName})p[{m}])";
451 break;
452 }
453 }
454 }
455 WriteMember(new SourceInfo(text4, text4, null, null, ilg), choiceSource, memberMapping2.ElementsSortedByDerivation, memberMapping2.Text, memberMapping2.ChoiceIdentifier, memberMapping2.TypeDesc, writeAccessors || hasWrapperElement);
456 if (sourceInfo2 != null)
457 {
458 ilg.EndIf();
459 }
460 ilg.EndIf();
461 }
463 {
465 }
466 ilg.EndMethod();
467 return text;
468 }
469
470 [RequiresUnreferencedCode("calls WriteMember")]
472 {
474 TypeMapping mapping = accessor.Mapping;
475 string text = NextMethodName(accessor.Name);
477 ilg.BeginMethod(typeof(void), text, new Type[1] { typeof(object) }, new string[1] { "o" }, MethodAttributes.Public | MethodAttributes.HideBySig);
478 MethodInfo method = typeof(XmlSerializationWriter).GetMethod("WriteStartDocument", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
479 ilg.Ldarg(0);
480 ilg.Call(method);
481 ilg.If(ilg.GetArg("o"), Cmp.EqualTo, null);
482 if (accessor.IsNullable)
483 {
484 WriteLiteralNullTag(accessor.Name, (accessor.Form == XmlSchemaForm.Qualified) ? accessor.Namespace : "");
485 }
486 else
487 {
488 WriteEmptyTag(accessor.Name, (accessor.Form == XmlSchemaForm.Qualified) ? accessor.Namespace : "");
489 }
491 ilg.EndIf();
492 if (!mapping.TypeDesc.IsValueType && !mapping.TypeDesc.Type.IsPrimitive)
493 {
494 MethodInfo method2 = typeof(XmlSerializationWriter).GetMethod("TopLevelElement", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
495 ilg.Ldarg(0);
497 }
498 WriteMember(new SourceInfo("o", "o", null, typeof(object), ilg), null, new ElementAccessor[1] { accessor }, null, null, mapping.TypeDesc, writeAccessors: true);
499 ilg.EndMethod();
500 return text;
501 }
502
503 private string NextMethodName(string name)
504 {
505 return "Write" + (++base.NextMethodNumber).ToString(null, NumberFormatInfo.InvariantInfo) + "_" + CodeIdentifier.MakeValidInternal(name);
506 }
507
509 {
510 base.MethodNames.TryGetValue(mapping, out var value);
511 List<Type> list = new List<Type>();
513 list.Add(mapping.TypeDesc.Type);
514 list2.Add("v");
516 ilg.BeginMethod(typeof(string), GetMethodBuilder(value), list.ToArray(), list2.ToArray(), MethodAttributes.Private | MethodAttributes.HideBySig);
518 ilg.Load(null);
520 ConstantMapping[] constants = mapping.Constants;
521 if (constants.Length != 0)
522 {
528 LocalBuilder localBuilder2 = ilg.DeclareLocal(mapping.TypeDesc.Type, "localTmp");
529 ilg.Ldarg("v");
532 {
533 if (hashSet.Add(constantMapping.Value))
534 {
537 ilg.Ldc(Enum.ToObject(mapping.TypeDesc.Type, constantMapping.Value));
538 ilg.Beq(label3);
541 }
542 }
543 if (mapping.IsFlags)
544 {
545 ilg.Br(label);
546 for (int j = 0; j < list3.Count; j++)
547 {
549 ilg.Ldc(list4[j]);
551 ilg.Br(label2);
552 }
554 base.RaCodeGen.ILGenForEnumLongValue(ilg, "v");
555 LocalBuilder localBuilder3 = ilg.DeclareLocal(typeof(string[]), "strArray");
556 ilg.NewArray(typeof(string), constants.Length);
558 for (int k = 0; k < constants.Length; k++)
559 {
562 ilg.Ldc(k);
564 ilg.Stelem(typeof(string));
565 }
567 LocalBuilder localBuilder4 = ilg.DeclareLocal(typeof(long[]), "longArray");
568 ilg.NewArray(typeof(long), constants.Length);
570 for (int l = 0; l < constants.Length; l++)
571 {
574 ilg.Ldc(l);
575 ilg.Ldc(constantMapping3.Value);
576 ilg.Stelem(typeof(long));
577 }
579 ilg.Ldstr(GetCSharpString(mapping.TypeDesc.FullName));
580 MethodInfo method = typeof(XmlSerializationWriter).GetMethod("FromEnum", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, new Type[4]
581 {
582 typeof(long),
583 typeof(string[]),
584 typeof(long[]),
585 typeof(string)
586 });
587 ilg.Call(method);
589 ilg.Br(label2);
590 }
591 else
592 {
593 ilg.Br(label);
594 for (int m = 0; m < list3.Count; m++)
595 {
597 ilg.Ldc(list4[m]);
599 ilg.Br(label2);
600 }
601 MethodInfo method2 = typeof(CultureInfo).GetMethod("get_InvariantCulture", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
602 MethodInfo method3 = typeof(long).GetMethod("ToString", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { typeof(IFormatProvider) });
603 MethodInfo method4 = typeof(XmlSerializationWriter).GetMethod("CreateInvalidEnumValueException", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[2]
604 {
605 typeof(object),
606 typeof(string)
607 });
609 ilg.Ldarg(0);
610 ilg.Ldarg("v");
611 ilg.ConvertValue(mapping.TypeDesc.Type, typeof(long));
617 ilg.Ldstr(GetCSharpString(mapping.TypeDesc.FullName));
619 ilg.Throw();
620 }
622 }
624 ilg.EndMethod();
625 }
626
628 {
629 for (StructMapping structMapping = mapping.DerivedMappings; structMapping != null; structMapping = structMapping.NextDerivedMapping)
630 {
631 ilg.InitElseIf();
632 WriteTypeCompare("t", structMapping.TypeDesc.Type);
633 ilg.AndIf();
635 List<Type> list = new List<Type>();
636 ilg.Ldarg(0);
637 list.Add(typeof(string));
638 ilg.Ldarg("n");
639 list.Add(typeof(string));
640 ilg.Ldarg("ns");
641 object variable = ilg.GetVariable("o");
645 list.Add(structMapping.TypeDesc.Type);
646 if (structMapping.TypeDesc.IsNullable)
647 {
648 list.Add(typeof(bool));
649 ilg.Ldarg("isNullable");
650 }
651 list.Add(typeof(bool));
652 ilg.Ldc(boolVar: true);
657 }
658 }
659
660 [RequiresUnreferencedCode("calls WriteMember")]
662 {
663 TypeScope[] scopes = base.Scopes;
664 foreach (TypeScope typeScope in scopes)
665 {
666 foreach (Mapping typeMapping in typeScope.TypeMappings)
667 {
669 {
671 ilg.InitElseIf();
672 WriteTypeCompare("t", enumMapping.TypeDesc.Type);
673 ilg.AndIf();
675 MethodInfo method = typeof(XmlSerializationWriter).GetMethod("get_Writer", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
676 MethodInfo method2 = typeof(XmlWriter).GetMethod("WriteStartElement", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[2]
677 {
678 typeof(string),
679 typeof(string)
680 });
681 ilg.Ldarg(0);
682 ilg.Call(method);
683 ilg.Ldarg("n");
684 ilg.Ldarg("ns");
686 MethodInfo method3 = typeof(XmlSerializationWriter).GetMethod("WriteXsiType", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[2]
687 {
688 typeof(string),
689 typeof(string)
690 });
691 ilg.Ldarg(0);
696 MethodInfo method4 = typeof(XmlWriter).GetMethod("WriteString", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { typeof(string) });
697 ilg.Ldarg(0);
698 ilg.Call(method);
699 object variable = ilg.GetVariable("o");
700 ilg.Ldarg(0);
705 MethodInfo method5 = typeof(XmlWriter).GetMethod("WriteEndElement", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
706 ilg.Ldarg(0);
707 ilg.Call(method);
710 }
712 {
713 ilg.InitElseIf();
714 if (arrayMapping.TypeDesc.IsArray)
715 {
716 WriteArrayTypeCompare("t", arrayMapping.TypeDesc.Type);
717 }
718 else
719 {
720 WriteTypeCompare("t", arrayMapping.TypeDesc.Type);
721 }
722 ilg.AndIf();
723 ilg.EnterScope();
724 MethodInfo method6 = typeof(XmlSerializationWriter).GetMethod("get_Writer", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
725 MethodInfo method7 = typeof(XmlWriter).GetMethod("WriteStartElement", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[2]
726 {
727 typeof(string),
728 typeof(string)
729 });
730 ilg.Ldarg(0);
732 ilg.Ldarg("n");
733 ilg.Ldarg("ns");
735 MethodInfo method8 = typeof(XmlSerializationWriter).GetMethod("WriteXsiType", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[2]
736 {
737 typeof(string),
738 typeof(string)
739 });
740 ilg.Ldarg(0);
744 WriteMember(new SourceInfo("o", "o", null, null, ilg), null, arrayMapping.ElementsSortedByDerivation, null, null, arrayMapping.TypeDesc, writeAccessors: true);
745 MethodInfo method9 = typeof(XmlWriter).GetMethod("WriteEndElement", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
746 ilg.Ldarg(0);
750 ilg.ExitScope();
751 }
752 }
753 }
754 }
755
756 [RequiresUnreferencedCode("Calls WriteMember")]
758 {
759 base.MethodNames.TryGetValue(mapping, out var value);
761 List<Type> list = new List<Type>(5);
763 list.Add(typeof(string));
764 list2.Add("n");
765 list.Add(typeof(string));
766 list2.Add("ns");
767 list.Add(mapping.TypeDesc.Type);
768 list2.Add("o");
769 if (mapping.TypeDesc.IsNullable)
770 {
771 list.Add(typeof(bool));
772 list2.Add("isNullable");
773 }
774 list.Add(typeof(bool));
775 list2.Add("needType");
776 ilg.BeginMethod(typeof(void), GetMethodBuilder(value), list.ToArray(), list2.ToArray(), MethodAttributes.Private | MethodAttributes.HideBySig);
777 if (mapping.TypeDesc.IsNullable)
778 {
779 ilg.If(ilg.GetArg("o"), Cmp.EqualTo, null);
780 ilg.If(ilg.GetArg("isNullable"), Cmp.EqualTo, true);
781 MethodInfo method = typeof(XmlSerializationWriter).GetMethod("WriteNullTagLiteral", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[2]
782 {
783 typeof(string),
784 typeof(string)
785 });
786 ilg.Ldarg(0);
787 ilg.Ldarg("n");
788 ilg.Ldarg("ns");
789 ilg.Call(method);
790 ilg.EndIf();
792 ilg.EndIf();
793 }
794 ilg.If(ilg.GetArg("needType"), Cmp.NotEqualTo, true);
796 MethodInfo method2 = typeof(object).GetMethod("GetType", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
797 ArgBuilder arg = ilg.GetArg("o");
799 ilg.ConvertAddress(arg.ArgType, typeof(object));
801 ilg.Stloc(local);
802 WriteTypeCompare("t", mapping.TypeDesc.Type);
803 ilg.If();
805 if (mapping.TypeDesc.IsRoot)
806 {
808 }
809 ilg.Else();
810 if (mapping.TypeDesc.IsRoot)
811 {
812 MethodInfo method3 = typeof(XmlSerializationWriter).GetMethod("WriteTypedPrimitive", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[4]
813 {
814 typeof(string),
815 typeof(string),
816 typeof(object),
817 typeof(bool)
818 });
819 ilg.Ldarg(0);
820 ilg.Ldarg("n");
821 ilg.Ldarg("ns");
822 ilg.Ldarg("o");
823 ilg.Ldc(boolVar: true);
826 }
827 else
828 {
829 MethodInfo method4 = typeof(XmlSerializationWriter).GetMethod("CreateUnknownTypeException", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { typeof(object) });
830 ilg.Ldarg(0);
831 ilg.Ldarg(arg);
832 ilg.ConvertValue(arg.ArgType, typeof(object));
834 ilg.Throw();
835 }
836 ilg.EndIf();
837 ilg.EndIf();
838 if (!mapping.TypeDesc.IsAbstract)
839 {
840 if (mapping.TypeDesc.Type != null && typeof(XmlSchemaObject).IsAssignableFrom(mapping.TypeDesc.Type))
841 {
842 MethodInfo method5 = typeof(XmlSerializationWriter).GetMethod("set_EscapeName", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { typeof(bool) });
843 ilg.Ldarg(0);
844 ilg.Ldc(boolVar: false);
846 }
847 string text = null;
849 int num = FindXmlnsIndex(allMembers);
850 if (num >= 0)
851 {
854 text = base.RaCodeGen.GetStringForMember("o", memberMapping.Name, mapping.TypeDesc);
855 }
856 ilg.Ldarg(0);
857 ilg.Ldarg("n");
858 ilg.Ldarg("ns");
859 ArgBuilder arg2 = ilg.GetArg("o");
860 ilg.Ldarg(arg2);
861 ilg.ConvertValue(arg2.ArgType, typeof(object));
862 ilg.Ldc(boolVar: false);
863 if (text == null)
864 {
865 ilg.Load(null);
866 }
867 else
868 {
870 }
871 MethodInfo method6 = typeof(XmlSerializationWriter).GetMethod("WriteStartElement", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[5]
872 {
873 typeof(string),
874 typeof(string),
875 typeof(object),
876 typeof(bool),
877 typeof(XmlSerializerNamespaces)
878 });
880 if (!mapping.TypeDesc.IsRoot)
881 {
882 ilg.If(ilg.GetArg("needType"), Cmp.EqualTo, true);
883 MethodInfo method7 = typeof(XmlSerializationWriter).GetMethod("WriteXsiType", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[2]
884 {
885 typeof(string),
886 typeof(string)
887 });
888 ilg.Ldarg(0);
889 ilg.Ldstr(GetCSharpString(mapping.TypeName));
890 ilg.Ldstr(GetCSharpString(mapping.Namespace));
892 ilg.EndIf();
893 }
895 {
896 if (memberMapping2.Attribute != null)
897 {
899 if (memberMapping2.CheckShouldPersist)
900 {
902 ilg.Call(memberMapping2.CheckShouldPersistMethodInfo);
903 ilg.If();
904 }
905 if (memberMapping2.CheckSpecified != 0)
906 {
907 string stringForMember = base.RaCodeGen.GetStringForMember("o", memberMapping2.Name + "Specified", mapping.TypeDesc);
909 ilg.If();
910 }
911 WriteMember(base.RaCodeGen.GetSourceForMember("o", memberMapping2, mapping.TypeDesc, ilg), memberMapping2.Attribute, memberMapping2.TypeDesc, "o");
912 if (memberMapping2.CheckSpecified != 0)
913 {
914 ilg.EndIf();
915 }
916 if (memberMapping2.CheckShouldPersist)
917 {
918 ilg.EndIf();
919 }
920 }
921 }
923 {
924 if (memberMapping3.Xmlns == null)
925 {
928 if (flag)
929 {
931 ilg.Call(memberMapping3.CheckShouldPersistMethodInfo);
932 ilg.If();
933 }
934 if (memberMapping3.CheckSpecified != 0)
935 {
936 string stringForMember2 = base.RaCodeGen.GetStringForMember("o", memberMapping3.Name + "Specified", mapping.TypeDesc);
938 ilg.If();
939 }
940 string choiceSource = null;
941 if (memberMapping3.ChoiceIdentifier != null)
942 {
943 CodeIdentifier.CheckValidIdentifier(memberMapping3.ChoiceIdentifier.MemberName);
944 choiceSource = base.RaCodeGen.GetStringForMember("o", memberMapping3.ChoiceIdentifier.MemberName, mapping.TypeDesc);
945 }
946 WriteMember(base.RaCodeGen.GetSourceForMember("o", memberMapping3, memberMapping3.MemberInfo, mapping.TypeDesc, ilg), choiceSource, memberMapping3.ElementsSortedByDerivation, memberMapping3.Text, memberMapping3.ChoiceIdentifier, memberMapping3.TypeDesc, writeAccessors: true);
947 if (memberMapping3.CheckSpecified != 0)
948 {
949 ilg.EndIf();
950 }
951 if (flag)
952 {
953 ilg.EndIf();
954 }
955 }
956 }
957 WriteEndElement("o");
958 }
959 ilg.EndMethod();
960 }
961
963 {
964 if (listElementTypeDesc != null)
965 {
966 return listElementTypeDesc != base.QnameTypeDesc;
967 }
968 return false;
969 }
970
971 [RequiresUnreferencedCode("calls WriteAttribute")]
973 {
974 if (memberTypeDesc.IsAbstract)
975 {
976 return;
977 }
978 if (memberTypeDesc.IsArrayLike)
979 {
980 string text = "a" + memberTypeDesc.Name;
981 string text2 = "ai" + memberTypeDesc.Name;
982 string text3 = "i";
983 string cSharpName = memberTypeDesc.CSharpName;
984 ilg.EnterScope();
986 if (memberTypeDesc.IsNullable)
987 {
989 ilg.Load(null);
990 ilg.If(Cmp.NotEqualTo);
991 }
992 if (attribute.IsList)
993 {
994 if (CanOptimizeWriteListSequence(memberTypeDesc.ArrayElementTypeDesc))
995 {
996 string value = ((attribute.Form == XmlSchemaForm.Qualified) ? attribute.Namespace : string.Empty);
997 MethodInfo method = typeof(XmlSerializationWriter).GetMethod("get_Writer", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
998 MethodInfo method2 = typeof(XmlWriter).GetMethod("WriteStartAttribute", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[3]
999 {
1000 typeof(string),
1001 typeof(string),
1002 typeof(string)
1003 });
1004 ilg.Ldarg(0);
1005 ilg.Call(method);
1006 ilg.Load(null);
1009 ilg.Call(method2);
1010 }
1011 else
1012 {
1014 ConstructorInfo constructor = typeof(StringBuilder).GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
1016 ilg.Stloc(local);
1017 }
1018 }
1019 TypeDesc arrayElementTypeDesc = memberTypeDesc.ArrayElementTypeDesc;
1020 if (memberTypeDesc.IsEnumerable)
1021 {
1022 throw Globals.NotSupported("Also fail in IEnumerable member with XmlAttributeAttribute");
1023 }
1025 ilg.For(local2, 0, ilg.GetLocal(text));
1026 WriteLocalDecl(text2, base.RaCodeGen.GetStringForArrayMember(text, text3, memberTypeDesc), arrayElementTypeDesc.Type);
1027 if (attribute.IsList)
1028 {
1029 Type returnType = typeof(string);
1030 string name;
1032 if (CanOptimizeWriteListSequence(memberTypeDesc.ArrayElementTypeDesc))
1033 {
1034 ilg.Ldloc(text3);
1035 ilg.Ldc(0);
1036 ilg.If(Cmp.NotEqualTo);
1037 MethodInfo method3 = typeof(XmlSerializationWriter).GetMethod("get_Writer", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
1038 MethodInfo method4 = typeof(XmlWriter).GetMethod("WriteString", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { typeof(string) });
1039 ilg.Ldarg(0);
1040 ilg.Call(method3);
1041 ilg.Ldstr(" ");
1042 ilg.Call(method4);
1043 ilg.EndIf();
1044 ilg.Ldarg(0);
1045 name = "WriteValue";
1047 }
1048 else
1049 {
1050 MethodInfo method5 = typeof(StringBuilder).GetMethod("Append", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { typeof(string) });
1051 ilg.Ldloc(text3);
1052 ilg.Ldc(0);
1053 ilg.If(Cmp.NotEqualTo);
1054 ilg.Ldloc("sb");
1055 ilg.Ldstr(" ");
1056 ilg.Call(method5);
1057 ilg.Pop();
1058 ilg.EndIf();
1059 ilg.Ldloc("sb");
1060 name = "Append";
1062 }
1063 if (attribute.Mapping is EnumMapping)
1064 {
1066 }
1067 else
1068 {
1070 }
1071 MethodInfo method6 = typeFromHandle.GetMethod(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { returnType });
1072 ilg.Call(method6);
1073 if (method6.ReturnType != typeof(void))
1074 {
1075 ilg.Pop();
1076 }
1077 }
1078 else
1079 {
1080 WriteAttribute(new SourceInfo(text2, text2, null, null, ilg), attribute, parent);
1081 }
1082 if (memberTypeDesc.IsEnumerable)
1083 {
1084 throw Globals.NotSupported("Also fail in whidbey IEnumerable member with XmlAttributeAttribute");
1085 }
1086 ilg.EndFor();
1087 if (attribute.IsList)
1088 {
1089 if (CanOptimizeWriteListSequence(memberTypeDesc.ArrayElementTypeDesc))
1090 {
1091 MethodInfo method7 = typeof(XmlSerializationWriter).GetMethod("get_Writer", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
1092 MethodInfo method8 = typeof(XmlWriter).GetMethod("WriteEndAttribute", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
1093 ilg.Ldarg(0);
1094 ilg.Call(method7);
1095 ilg.Call(method8);
1096 }
1097 else
1098 {
1099 MethodInfo method9 = typeof(StringBuilder).GetMethod("get_Length", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
1100 ilg.Ldloc("sb");
1101 ilg.Call(method9);
1102 ilg.Ldc(0);
1103 ilg.If(Cmp.NotEqualTo);
1104 List<Type> list = new List<Type>();
1105 ilg.Ldarg(0);
1107 list.Add(typeof(string));
1108 string text4 = ((attribute.Form == XmlSchemaForm.Qualified) ? attribute.Namespace : string.Empty);
1109 if (text4 != null)
1110 {
1112 list.Add(typeof(string));
1113 }
1114 MethodInfo method10 = typeof(object).GetMethod("ToString", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
1115 ilg.Ldloc("sb");
1116 ilg.Call(method10);
1117 list.Add(typeof(string));
1118 MethodInfo method11 = typeof(XmlSerializationWriter).GetMethod("WriteAttribute", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, list.ToArray());
1119 ilg.Call(method11);
1120 ilg.EndIf();
1121 }
1122 }
1123 if (memberTypeDesc.IsNullable)
1124 {
1125 ilg.EndIf();
1126 }
1127 ilg.ExitScope();
1128 }
1129 else
1130 {
1132 }
1133 }
1134
1135 [RequiresUnreferencedCode("calls WritePrimitive")]
1137 {
1138 if (attribute.Mapping is SpecialMapping)
1139 {
1141 if (specialMapping.TypeDesc.Kind != TypeKind.Attribute && !specialMapping.TypeDesc.CanBeAttributeValue)
1142 {
1144 }
1145 MethodInfo method = typeof(XmlSerializationWriter).GetMethod("WriteXmlAttribute", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[2]
1146 {
1147 typeof(XmlNode),
1148 typeof(object)
1149 });
1150 ilg.Ldarg(0);
1151 ilg.Ldloc(source.Source);
1152 ilg.Ldarg(parent);
1153 ilg.ConvertValue(ilg.GetArg(parent).ArgType, typeof(object));
1154 ilg.Call(method);
1155 }
1156 else
1157 {
1158 TypeDesc typeDesc = attribute.Mapping.TypeDesc;
1159 source = source.CastTo(typeDesc);
1160 WritePrimitive("WriteAttribute", attribute.Name, (attribute.Form == XmlSchemaForm.Qualified) ? attribute.Namespace : "", GetConvertedDefaultValue(source.Type, attribute.Default), source, attribute.Mapping, writeXsiType: false, isElement: false, isNullable: false);
1161 }
1162 }
1163
1165 {
1166 if (targetType == null)
1167 {
1168 return rawDefaultValue;
1169 }
1170 if (!targetType.TryConvertTo(rawDefaultValue, out var returnValue))
1171 {
1172 return rawDefaultValue;
1173 }
1174 return returnValue;
1175 }
1176
1177 [RequiresUnreferencedCode("Calls WriteElements")]
1179 {
1180 if (memberTypeDesc.IsArrayLike && (elements.Length != 1 || !(elements[0].Mapping is ArrayMapping)))
1181 {
1183 }
1184 else
1185 {
1187 }
1188 }
1189
1190 [RequiresUnreferencedCode("calls WriteArrayItems")]
1192 {
1193 if (elements.Length != 0 || text != null)
1194 {
1195 string cSharpName = arrayTypeDesc.CSharpName;
1196 string text2 = "a" + arrayTypeDesc.Name;
1197 ilg.EnterScope();
1200 if (arrayTypeDesc.IsNullable)
1201 {
1202 ilg.Ldloc(local);
1203 ilg.Load(null);
1204 ilg.If(Cmp.NotEqualTo);
1205 }
1206 string text3 = null;
1207 if (choice != null)
1208 {
1209 string cSharpName2 = choice.Mapping.TypeDesc.CSharpName;
1210 SourceInfo initValue = new SourceInfo(choiceSource, null, choice.MemberInfo, null, ilg);
1211 text3 = "c" + choice.Mapping.TypeDesc.Name;
1212 WriteArrayLocalDecl(cSharpName2 + "[]", text3, initValue, choice.Mapping.TypeDesc);
1216 ilg.Ldloc(local2);
1217 ilg.Load(null);
1218 ilg.Beq(label2);
1219 ilg.Ldloc(local2);
1220 ilg.Ldlen();
1221 ilg.Ldloc(local);
1222 ilg.Ldlen();
1223 ilg.Clt();
1224 ilg.Br(label);
1226 ilg.Ldc(boolVar: true);
1228 ilg.If();
1229 MethodInfo method = typeof(XmlSerializationWriter).GetMethod("CreateInvalidChoiceIdentifierValueException", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[2]
1230 {
1231 typeof(string),
1232 typeof(string)
1233 });
1234 ilg.Ldarg(0);
1235 ilg.Ldstr(GetCSharpString(choice.Mapping.TypeDesc.FullName));
1236 ilg.Ldstr(GetCSharpString(choice.MemberName));
1237 ilg.Call(method);
1238 ilg.Throw();
1239 ilg.EndIf();
1240 }
1242 if (arrayTypeDesc.IsNullable)
1243 {
1244 ilg.EndIf();
1245 }
1246 ilg.ExitScope();
1247 }
1248 }
1249
1250 [RequiresUnreferencedCode("calls WriteElements")]
1252 {
1253 TypeDesc arrayElementTypeDesc = arrayTypeDesc.ArrayElementTypeDesc;
1254 if (arrayTypeDesc.IsEnumerable)
1255 {
1259 if (arrayTypeDesc.IsPrivateImplementation)
1260 {
1262 method = typeFromHandle.GetMethod("GetEnumerator", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
1264 }
1265 else if (arrayTypeDesc.IsGenericInterface)
1266 {
1268 method = type.GetMethod("GetEnumerator", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
1270 }
1271 else
1272 {
1273 method = arrayTypeDesc.Type.GetMethod("GetEnumerator", Type.EmptyTypes);
1274 }
1275 ilg.Call(method);
1279 ilg.Load(null);
1280 ilg.If(Cmp.NotEqualTo);
1281 ilg.WhileBegin();
1282 string arrayName2 = arrayName.Replace(arrayTypeDesc.Name, "") + "a" + arrayElementTypeDesc.Name;
1283 string text2 = arrayName.Replace(arrayTypeDesc.Name, "") + "i" + arrayElementTypeDesc.Name;
1284 WriteLocalDecl(text2, "e.Current", arrayElementTypeDesc.Type);
1285 WriteElements(new SourceInfo(text2, null, null, arrayElementTypeDesc.Type, ilg), choiceName + "i", elements, text, choice, arrayName2, writeAccessors: true, isNullable: true);
1287 MethodInfo method2 = typeof(IEnumerator).GetMethod("MoveNext", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
1289 ilg.Call(method2);
1291 ilg.WhileEnd();
1292 ilg.EndIf();
1293 return;
1294 }
1295 string text3 = "i" + arrayName.Replace(arrayTypeDesc.Name, "");
1296 string arrayName3 = arrayName.Replace(arrayTypeDesc.Name, "") + "a" + arrayElementTypeDesc.Name;
1297 string text4 = arrayName.Replace(arrayTypeDesc.Name, "") + "i" + arrayElementTypeDesc.Name;
1300 int num = elements.Length + ((text != null) ? 1 : 0);
1301 if (num > 1)
1302 {
1303 WriteLocalDecl(text4, base.RaCodeGen.GetStringForArrayMember(arrayName, text3, arrayTypeDesc), arrayElementTypeDesc.Type);
1304 if (choice != null)
1305 {
1306 WriteLocalDecl(choiceName + "i", base.RaCodeGen.GetStringForArrayMember(choiceName, text3, choice.Mapping.TypeDesc), choice.Mapping.TypeDesc.Type);
1307 }
1308 WriteElements(new SourceInfo(text4, null, null, arrayElementTypeDesc.Type, ilg), choiceName + "i", elements, text, choice, arrayName3, writeAccessors: true, arrayElementTypeDesc.IsNullable);
1309 }
1310 else
1311 {
1312 WriteElements(new SourceInfo(base.RaCodeGen.GetStringForArrayMember(arrayName, text3, arrayTypeDesc), null, null, arrayElementTypeDesc.Type, ilg), null, elements, text, choice, arrayName3, writeAccessors: true, arrayElementTypeDesc.IsNullable);
1313 }
1314 ilg.EndFor();
1315 }
1316
1317 [RequiresUnreferencedCode("Calls WriteElement")]
1319 {
1320 if (elements.Length == 0 && text == null)
1321 {
1322 return;
1323 }
1324 if (elements.Length == 1 && text == null)
1325 {
1326 TypeDesc td = (elements[0].IsUnbounded ? elements[0].Mapping.TypeDesc.CreateArrayTypeDesc() : elements[0].Mapping.TypeDesc);
1327 if (!elements[0].Any && !elements[0].Mapping.TypeDesc.IsOptionalValue)
1328 {
1329 source = source.CastTo(td);
1330 }
1332 return;
1333 }
1334 bool flag = false;
1335 if (isNullable && choice == null)
1336 {
1337 source.Load(typeof(object));
1338 ilg.Load(null);
1339 ilg.If(Cmp.NotEqualTo);
1340 flag = true;
1341 }
1342 int num = 0;
1345 bool flag2 = false;
1346 string text2 = choice?.Mapping.TypeDesc.FullName;
1347 foreach (ElementAccessor elementAccessor2 in elements)
1348 {
1349 if (elementAccessor2.Any)
1350 {
1351 num++;
1352 if (elementAccessor2.Name != null && elementAccessor2.Name.Length > 0)
1353 {
1355 }
1356 else if (elementAccessor == null)
1357 {
1359 }
1360 }
1361 else if (choice != null)
1362 {
1363 string cSharpName = elementAccessor2.Mapping.TypeDesc.CSharpName;
1364 object eValue;
1366 if (flag2)
1367 {
1368 ilg.InitElseIf();
1369 }
1370 else
1371 {
1372 flag2 = true;
1373 ilg.InitIf();
1374 }
1375 ILGenLoad(enumSource, choice?.Mapping.TypeDesc.Type);
1376 ilg.Load(eValue);
1377 ilg.Ceq();
1378 if (isNullable && !elementAccessor2.IsNullable)
1379 {
1382 ilg.Brfalse(label);
1383 source.Load(typeof(object));
1384 ilg.Load(null);
1385 ilg.Cne();
1386 ilg.Br_S(label2);
1388 ilg.Ldc(boolVar: false);
1390 }
1391 ilg.AndIf();
1393 SourceInfo sourceInfo = source.CastTo(elementAccessor2.Mapping.TypeDesc);
1395 }
1396 else
1397 {
1398 TypeDesc typeDesc = (elementAccessor2.IsUnbounded ? elementAccessor2.Mapping.TypeDesc.CreateArrayTypeDesc() : elementAccessor2.Mapping.TypeDesc);
1399 if (flag2)
1400 {
1401 ilg.InitElseIf();
1402 }
1403 else
1404 {
1405 flag2 = true;
1406 ilg.InitIf();
1407 }
1409 ilg.AndIf();
1412 }
1413 }
1414 if (flag2 && num > 0 && elements.Length - num <= 0)
1415 {
1416 ilg.EndIf();
1417 }
1418 if (num > 0)
1419 {
1420 if (elements.Length - num > 0)
1421 {
1422 ilg.InitElseIf();
1423 }
1424 else
1425 {
1426 ilg.InitIf();
1427 }
1428 source.Load(typeof(object));
1430 ilg.Load(null);
1431 ilg.Cne();
1432 ilg.AndIf();
1434 source.Load(typeof(XmlElement));
1436 int num2 = 0;
1437 foreach (ElementAccessor item in list)
1438 {
1439 if (num2++ > 0)
1440 {
1441 ilg.InitElseIf();
1442 }
1443 else
1444 {
1445 ilg.InitIf();
1446 }
1447 string value = null;
1448 Label label3;
1449 Label label4;
1450 if (choice != null)
1451 {
1455 ILGenLoad(enumSource, choice?.Mapping.TypeDesc.Type);
1456 ilg.Load(eValue2);
1457 ilg.Bne(label3);
1458 if (isNullable && !item.IsNullable)
1459 {
1460 source.Load(typeof(object));
1461 ilg.Load(null);
1462 ilg.Cne();
1463 }
1464 else
1465 {
1466 ilg.Ldc(boolVar: true);
1467 }
1468 ilg.Br(label4);
1470 ilg.Ldc(boolVar: false);
1472 ilg.AndIf();
1473 }
1476 MethodInfo method = typeof(XmlNode).GetMethod("get_Name", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
1477 MethodInfo method2 = typeof(XmlNode).GetMethod("get_NamespaceURI", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
1479 ilg.Call(method);
1481 MethodInfo method3 = typeof(string).GetMethod("op_Equality", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, new Type[2]
1482 {
1483 typeof(string),
1484 typeof(string)
1485 });
1486 ilg.Call(method3);
1489 ilg.Call(method2);
1490 ilg.Ldstr(GetCSharpString(item.Namespace));
1491 ilg.Call(method3);
1492 ilg.Br(label4);
1494 ilg.Ldc(boolVar: false);
1496 if (choice != null)
1497 {
1498 ilg.If();
1499 }
1500 else
1501 {
1502 ilg.AndIf();
1503 }
1504 WriteElement(new SourceInfo("elem", null, null, localBuilder.LocalType, ilg), item, arrayName, writeAccessors);
1505 if (choice != null)
1506 {
1507 ilg.Else();
1508 MethodInfo method4 = typeof(XmlSerializationWriter).GetMethod("CreateChoiceIdentifierValueException", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[4]
1509 {
1510 typeof(string),
1511 typeof(string),
1512 typeof(string),
1513 typeof(string)
1514 });
1515 ilg.Ldarg(0);
1517 ilg.Ldstr(GetCSharpString(choice.MemberName));
1519 ilg.Call(method);
1521 ilg.Call(method2);
1522 ilg.Call(method4);
1523 ilg.Throw();
1524 ilg.EndIf();
1525 }
1526 }
1527 if (num2 > 0)
1528 {
1529 ilg.Else();
1530 }
1531 if (elementAccessor != null)
1532 {
1533 WriteElement(new SourceInfo("elem", null, null, localBuilder.LocalType, ilg), elementAccessor, arrayName, writeAccessors);
1534 }
1535 else
1536 {
1537 MethodInfo method5 = typeof(XmlSerializationWriter).GetMethod("CreateUnknownAnyElementException", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[2]
1538 {
1539 typeof(string),
1540 typeof(string)
1541 });
1542 ilg.Ldarg(0);
1544 MethodInfo method6 = typeof(XmlNode).GetMethod("get_Name", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
1545 MethodInfo method7 = typeof(XmlNode).GetMethod("get_NamespaceURI", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
1546 ilg.Call(method6);
1548 ilg.Call(method7);
1549 ilg.Call(method5);
1550 ilg.Throw();
1551 }
1552 if (num2 > 0)
1553 {
1554 ilg.EndIf();
1555 }
1556 }
1557 if (text != null)
1558 {
1559 if (elements.Length != 0)
1560 {
1561 ilg.InitElseIf();
1562 WriteInstanceOf(source, text.Mapping.TypeDesc.Type);
1563 ilg.AndIf();
1564 SourceInfo source2 = source.CastTo(text.Mapping.TypeDesc);
1566 }
1567 else
1568 {
1569 SourceInfo source3 = source.CastTo(text.Mapping.TypeDesc);
1571 }
1572 }
1573 if (elements.Length != 0)
1574 {
1575 if (isNullable)
1576 {
1577 ilg.InitElseIf();
1578 source.Load(null);
1579 ilg.Load(null);
1580 ilg.AndIf(Cmp.NotEqualTo);
1581 }
1582 else
1583 {
1584 ilg.Else();
1585 }
1586 MethodInfo method8 = typeof(XmlSerializationWriter).GetMethod("CreateUnknownTypeException", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { typeof(object) });
1587 ilg.Ldarg(0);
1588 source.Load(typeof(object));
1589 ilg.Call(method8);
1590 ilg.Throw();
1591 ilg.EndIf();
1592 }
1593 if (flag)
1594 {
1595 ilg.EndIf();
1596 }
1597 }
1598
1599 [RequiresUnreferencedCode("calls Load")]
1601 {
1602 if (text.Mapping is PrimitiveMapping)
1603 {
1605 ilg.Ldarg(0);
1607 if (text.Mapping is EnumMapping)
1608 {
1610 }
1611 else
1612 {
1614 }
1615 MethodInfo method = typeof(XmlSerializationWriter).GetMethod("WriteValue", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { returnType });
1616 ilg.Call(method);
1617 }
1618 else if (text.Mapping is SpecialMapping)
1619 {
1621 TypeKind kind = specialMapping.TypeDesc.Kind;
1622 if (kind != TypeKind.Node)
1623 {
1625 }
1626 MethodInfo method2 = source.Type.GetMethod("WriteTo", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { typeof(XmlWriter) });
1627 MethodInfo method3 = typeof(XmlSerializationWriter).GetMethod("get_Writer", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
1628 source.Load(source.Type);
1629 ilg.Ldarg(0);
1630 ilg.Call(method3);
1631 ilg.Call(method2);
1632 }
1633 }
1634
1635 [RequiresUnreferencedCode("Calls WriteCheckDefault")]
1637 {
1638 string text = (writeAccessor ? element.Name : element.Mapping.TypeName);
1639 string text2 = ((element.Any && element.Name.Length == 0) ? null : ((element.Form != XmlSchemaForm.Qualified) ? "" : (writeAccessor ? element.Namespace : element.Mapping.Namespace)));
1640 if (element.Mapping is NullableMapping)
1641 {
1642 if (source.Type == element.Mapping.TypeDesc.Type)
1643 {
1644 MethodInfo method = element.Mapping.TypeDesc.Type.GetMethod("get_HasValue", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
1645 source.LoadAddress(element.Mapping.TypeDesc.Type);
1646 ilg.Call(method);
1647 }
1648 else
1649 {
1650 source.Load(null);
1651 ilg.Load(null);
1652 ilg.Cne();
1653 }
1654 ilg.If();
1657 elementAccessor.Mapping = ((NullableMapping)element.Mapping).BaseMapping;
1659 if (element.IsNullable)
1660 {
1661 ilg.Else();
1662 WriteLiteralNullTag(element.Name, (element.Form == XmlSchemaForm.Qualified) ? element.Namespace : "");
1663 }
1664 ilg.EndIf();
1665 return;
1666 }
1667 if (element.Mapping is ArrayMapping)
1668 {
1670 if (element.IsUnbounded)
1671 {
1672 throw Globals.NotSupported("Unreachable: IsUnbounded is never set true!");
1673 }
1674 ilg.EnterScope();
1675 string cSharpName = arrayMapping.TypeDesc.CSharpName;
1677 if (element.IsNullable)
1678 {
1680 }
1681 else if (arrayMapping.TypeDesc.IsNullable)
1682 {
1684 ilg.Load(null);
1685 ilg.If(Cmp.NotEqualTo);
1686 }
1688 WriteArrayItems(arrayMapping.ElementsSortedByDerivation, null, null, arrayMapping.TypeDesc, arrayName, null);
1690 if (element.IsNullable)
1691 {
1692 ilg.EndIf();
1693 }
1694 else if (arrayMapping.TypeDesc.IsNullable)
1695 {
1696 ilg.EndIf();
1697 }
1698 ilg.ExitScope();
1699 return;
1700 }
1701 if (element.Mapping is EnumMapping)
1702 {
1703 WritePrimitive("WriteElementString", text, text2, element.Default, source, element.Mapping, writeXsiType: false, isElement: true, element.IsNullable);
1704 return;
1705 }
1706 if (element.Mapping is PrimitiveMapping)
1707 {
1709 if (primitiveMapping.TypeDesc == base.QnameTypeDesc)
1710 {
1712 return;
1713 }
1715 WritePrimitive(element.IsNullable ? ("WriteNullableStringLiteral" + text3) : ("WriteElementString" + text3), text, text2, GetConvertedDefaultValue(source.Type, element.Default), source, primitiveMapping, writeXsiType: false, isElement: true, element.IsNullable);
1716 return;
1717 }
1718 if (element.Mapping is StructMapping)
1719 {
1722 List<Type> list = new List<Type>();
1723 ilg.Ldarg(0);
1725 list.Add(typeof(string));
1727 list.Add(typeof(string));
1728 source.Load(structMapping.TypeDesc.Type);
1729 list.Add(structMapping.TypeDesc.Type);
1730 if (structMapping.TypeDesc.IsNullable)
1731 {
1732 ilg.Ldc(element.IsNullable);
1733 list.Add(typeof(bool));
1734 }
1735 ilg.Ldc(boolVar: false);
1736 list.Add(typeof(bool));
1739 return;
1740 }
1741 if (element.Mapping is SpecialMapping)
1742 {
1743 if (element.Mapping is SerializableMapping)
1744 {
1745 WriteElementCall("WriteSerializable", typeof(IXmlSerializable), source, text, text2, element.IsNullable, !element.Any);
1746 return;
1747 }
1750 source.Load(null);
1752 ilg.Brtrue(label);
1753 source.Load(null);
1754 ilg.Load(null);
1755 ilg.Ceq();
1756 ilg.Br(label2);
1758 ilg.Ldc(boolVar: true);
1760 ilg.If();
1761 WriteElementCall("WriteElementLiteral", typeof(XmlNode), source, text, text2, element.IsNullable, element.Any);
1762 ilg.Else();
1763 MethodInfo method2 = typeof(XmlSerializationWriter).GetMethod("CreateInvalidAnyTypeException", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { typeof(object) });
1764 ilg.Ldarg(0);
1765 source.Load(null);
1766 ilg.Call(method2);
1767 ilg.Throw();
1768 ilg.EndIf();
1769 return;
1770 }
1772 }
1773
1774 [RequiresUnreferencedCode("XmlSerializationWriter methods have RequiresUnreferencedCode")]
1775 private void WriteElementCall(string func, Type cast, SourceInfo source, string name, string ns, bool isNullable, bool isAny)
1776 {
1777 MethodInfo method = typeof(XmlSerializationWriter).GetMethod(func, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[5]
1778 {
1779 cast,
1780 typeof(string),
1781 typeof(string),
1782 typeof(bool),
1783 typeof(bool)
1784 });
1785 ilg.Ldarg(0);
1786 source.Load(cast);
1787 ilg.Ldstr(GetCSharpString(name));
1790 ilg.Ldc(isAny);
1791 ilg.Call(method);
1792 }
1793
1794 [RequiresUnreferencedCode("Dynamically looks for '!=' operator on 'value' parameter")]
1796 {
1797 if (value is string && ((string)value).Length == 0)
1798 {
1802 source.Load(typeof(string));
1803 if (isNullable)
1804 {
1806 }
1807 else
1808 {
1810 }
1811 MethodInfo method = typeof(string).GetMethod("get_Length", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
1812 source.Load(typeof(string));
1813 ilg.Call(method);
1814 ilg.Ldc(0);
1815 ilg.Cne();
1816 ilg.Br(label);
1817 if (isNullable)
1818 {
1820 ilg.Ldc(boolVar: true);
1821 }
1822 else
1823 {
1825 ilg.Ldc(boolVar: false);
1826 }
1828 ilg.If();
1829 return;
1830 }
1831 if (value == null)
1832 {
1833 source.Load(typeof(object));
1834 ilg.Load(null);
1835 ilg.Cne();
1836 }
1837 else if (value.GetType().IsPrimitive)
1838 {
1839 source.Load(null);
1841 ilg.Cne();
1842 }
1843 else
1844 {
1845 Type type = value.GetType();
1846 source.Load(type);
1847 ilg.Ldc((value is string) ? GetCSharpString((string)value) : value);
1848 MethodInfo method2 = type.GetMethod("op_Inequality", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, new Type[2] { type, type });
1849 if (method2 != null)
1850 {
1851 ilg.Call(method2);
1852 }
1853 else
1854 {
1855 ilg.Cne();
1856 }
1857 }
1858 ilg.If();
1859 }
1860
1861 [RequiresUnreferencedCode("calls Load")]
1863 {
1864 Label label = ilg.DefineLabel();
1865 Label label2 = ilg.DefineLabel();
1866 source.Load(typeof(object));
1867 ilg.Load(null);
1868 ilg.Beq(label);
1869 WriteInstanceOf(source, typeDesc.Type);
1870 ilg.Ldc(boolVar: false);
1871 ilg.Ceq();
1872 ilg.Br(label2);
1873 ilg.MarkLabel(label);
1874 ilg.Ldc(boolVar: false);
1875 ilg.MarkLabel(label2);
1876 ilg.If();
1877 MethodInfo method = typeof(XmlSerializationWriter).GetMethod("CreateMismatchChoiceException", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[3]
1878 {
1879 typeof(string),
1880 typeof(string),
1881 typeof(string)
1882 });
1883 ilg.Ldarg(0);
1884 ilg.Ldstr(GetCSharpString(typeDesc.FullName));
1885 ilg.Ldstr(GetCSharpString(choice.MemberName));
1886 ilg.Ldstr(GetCSharpString(enumName));
1887 ilg.Call(method);
1888 ilg.Throw();
1889 ilg.EndIf();
1890 }
1891
1892 [RequiresUnreferencedCode("calls WriteLiteralNullTag")]
1893 private void WriteNullCheckBegin(string source, ElementAccessor element)
1894 {
1895 LocalBuilder local = ilg.GetLocal(source);
1896 ilg.Load(local);
1897 ilg.Load(null);
1898 ilg.If(Cmp.EqualTo);
1899 WriteLiteralNullTag(element.Name, (element.Form == XmlSchemaForm.Qualified) ? element.Namespace : "");
1900 ilg.Else();
1901 }
1902
1903 [RequiresUnreferencedCode("calls ILGenLoad")]
1904 private void WriteNamespaces(string source)
1905 {
1906 MethodInfo method = typeof(XmlSerializationWriter).GetMethod("WriteNamespaceDeclarations", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { typeof(XmlSerializerNamespaces) });
1907 ilg.Ldarg(0);
1909 ilg.Call(method);
1910 }
1911
1913 {
1914 for (int i = 0; i < members.Length; i++)
1915 {
1916 if (members[i].Xmlns != null)
1917 {
1918 return i;
1919 }
1920 }
1921 return -1;
1922 }
1923
1924 [RequiresUnreferencedCode("calls WriteLocalDecl")]
1925 private void WriteLocalDecl(string variableName, string initValue, Type type)
1926 {
1927 base.RaCodeGen.WriteLocalDecl(variableName, new SourceInfo(initValue, initValue, null, type, ilg));
1928 }
1929
1930 [RequiresUnreferencedCode("calls WriteArrayLocalDecl")]
1932 {
1933 base.RaCodeGen.WriteArrayLocalDecl(typeName, variableName, initValue, arrayTypeDesc);
1934 }
1935
1936 private void WriteTypeCompare(string variable, Type type)
1937 {
1938 base.RaCodeGen.WriteTypeCompare(variable, type, ilg);
1939 }
1940
1941 [RequiresUnreferencedCode("calls WriteInstanceOf")]
1943 {
1944 base.RaCodeGen.WriteInstanceOf(source, type, ilg);
1945 }
1946
1948 {
1949 base.RaCodeGen.WriteArrayTypeCompare(variable, arrayType, ilg);
1950 }
1951
1953 {
1954 string text = null;
1955 eValue = null;
1956 for (int i = 0; i < choiceMapping.Constants.Length; i++)
1957 {
1958 string xmlName = choiceMapping.Constants[i].XmlName;
1959 if (element.Any && element.Name.Length == 0)
1960 {
1961 if (xmlName == "##any:")
1962 {
1963 text = choiceMapping.Constants[i].Name;
1964 eValue = Enum.ToObject(choiceMapping.TypeDesc.Type, choiceMapping.Constants[i].Value);
1965 break;
1966 }
1967 continue;
1968 }
1969 int num = xmlName.LastIndexOf(':');
1970 string text2 = ((num < 0) ? choiceMapping.Namespace : xmlName.Substring(0, num));
1971 string text3 = ((num < 0) ? xmlName : xmlName.Substring(num + 1));
1972 if (element.Name == text3 && ((element.Form == XmlSchemaForm.Unqualified && string.IsNullOrEmpty(text2)) || element.Namespace == text2))
1973 {
1974 text = choiceMapping.Constants[i].Name;
1975 eValue = Enum.ToObject(choiceMapping.TypeDesc.Type, choiceMapping.Constants[i].Value);
1976 break;
1977 }
1978 }
1979 if (text == null || text.Length == 0)
1980 {
1981 if (element.Any && element.Name.Length == 0)
1982 {
1984 }
1985 throw new InvalidOperationException(System.SR.Format(System.SR.XmlChoiceMissingValue, choiceMapping.TypeDesc.FullName, element.Namespace + ":" + element.Name, element.Name, element.Namespace));
1986 }
1988 return text;
1989 }
1990}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void Add(TKey key, TValue value)
static ? object ChangeType(object? value, TypeCode typeCode)
Definition Convert.cs:229
static readonly DBNull Value
Definition DBNull.cs:8
static object Parse(Type enumType, string value)
Definition Enum.cs:368
static object ToObject(Type enumType, object value)
Definition Enum.cs:874
static CultureInfo InvariantCulture
ConstructorBuilder DefineDefaultConstructor(MethodAttributes attributes)
virtual Type AsType()
Definition TypeInfo.cs:106
static string XmlInternalError
Definition SR.cs:1812
static string XmlChoiceMissingAnyValue
Definition SR.cs:1656
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string XmlChoiceMissingValue
Definition SR.cs:1654
Definition SR.cs:7
static ? Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Definition Type.cs:408
virtual Type MakeGenericType(params Type[] typeArguments)
Definition Type.cs:1074
static readonly Type[] EmptyTypes
Definition Type.cs:19
MethodInfo? GetMethod(string name)
Definition Type.cs:675
void Stelem(Type arrayElementType)
void ConvertAddress(Type source, Type target)
void ConvertValue(Type source, Type target)
LocalBuilder DeclareLocal(Type type, string name)
LocalBuilder DeclareOrGetLocal(Type type, string name)
void New(ConstructorInfo constructorInfo)
void LdargAddress(ArgBuilder argBuilder)
void BeginMethod(Type returnType, string methodName, Type[] argTypes, string[] argNames, MethodAttributes methodAttributes)
static TypeBuilder CreateTypeBuilder(ModuleBuilder moduleBuilder, string name, TypeAttributes attributes, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type parent, Type[] interfaces)
void Call(MethodInfo methodInfo)
void NewArray(Type elementType, object len)
void Stloc(Type type, string name)
object For(LocalBuilder local, object start, object end)
LocalBuilder GetLocal(string name)
void LdlocAddress(LocalBuilder localBuilder)
void Ldloc(LocalBuilder localBuilder)
static void CheckValidIdentifier([NotNull] string ident)
static string MakeValidInternal(string identifier)
static Exception NotSupported(string msg)
Definition Globals.cs:5
static MemberMapping[] GetAllMembers(StructMapping mapping)
Definition TypeScope.cs:598
MethodBuilder EnsureMethodBuilder(TypeBuilder typeBuilder, string methodName, MethodAttributes attributes, Type returnType, Type[] parameterTypes)
MethodBuilderInfo GetMethodBuilder(string methodName)
static object GetConvertedDefaultValue([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type targetType, object rawDefaultValue)
void WriteArrayItems(ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc, string arrayName, string choiceName)
void WriteElements(SourceInfo source, string enumSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, string arrayName, bool writeAccessors, bool isNullable)
string FindChoiceEnumValue(ElementAccessor element, EnumMapping choiceMapping, out object eValue)
XmlSerializationWriterILGen(TypeScope[] scopes, string access, string className)
void WriteQualifiedNameElement(string name, string ns, object defaultValue, SourceInfo source, bool nullable, TypeMapping mapping)
void WriteAttribute(SourceInfo source, AttributeAccessor attribute, string parent)
void WriteCheckDefault(SourceInfo source, object value, bool isNullable)
void WriteArrayLocalDecl(string typeName, string variableName, SourceInfo initValue, TypeDesc arrayTypeDesc)
void WriteMember(SourceInfo source, AttributeAccessor attribute, TypeDesc memberTypeDesc, string parent)
void WriteNullCheckBegin(string source, ElementAccessor element)
void WriteTag(string methodName, string name, string ns)
void WriteChoiceTypeCheck(SourceInfo source, string fullTypeName, ChoiceIdentifierAccessor choice, string enumName, TypeDesc typeDesc)
string GenerateMembersElement(XmlMembersMapping xmlMembersMapping)
void WriteMember(SourceInfo source, string choiceSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc memberTypeDesc, bool writeAccessors)
void WriteArray(SourceInfo source, string choiceSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc)
void WriteEnumValue(EnumMapping mapping, SourceInfo source, out Type returnType)
void WritePrimitive(string method, string name, string ns, object defaultValue, SourceInfo source, TypeMapping mapping, bool writeXsiType, bool isElement, bool isNullable)
void WriteElementCall(string func, Type cast, SourceInfo source, string name, string ns, bool isNullable, bool isAny)
void WritePrimitiveValue(TypeDesc typeDesc, SourceInfo source, out Type returnType)
void WriteStartElement(string name, string ns, bool writePrefixed)
void WriteLocalDecl(string variableName, string initValue, Type type)
void WriteTag(string methodName, string name, string ns, bool writePrefixed)
void WriteElement(SourceInfo source, ElementAccessor element, string arrayName, bool writeAccessor)