Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ WriteElement()

void System.Xml.Serialization.XmlSerializationReaderILGen.WriteElement ( string source,
string arrayName,
string choiceSource,
ElementAccessor element,
ChoiceIdentifierAccessor choice,
string checkSpecified,
bool checkForNull,
bool readOnly,
int fixupIndex,
int elementIndex )
inlineprivate

Definition at line 2451 of file XmlSerializationReaderILGen.cs.

2452 {
2453 if (checkSpecified != null && checkSpecified.Length > 0)
2454 {
2455 ILGenSet(checkSpecified, true);
2456 }
2457 if (element.Mapping is ArrayMapping)
2458 {
2459 WriteArray(source, arrayName, (ArrayMapping)element.Mapping, readOnly, element.IsNullable, fixupIndex, elementIndex);
2460 }
2461 else if (element.Mapping is NullableMapping)
2462 {
2463 string methodName = ReferenceMapping(element.Mapping);
2465 ilg.Ldarg(0);
2466 ilg.Ldc(boolVar: true);
2467 MethodBuilder methodInfo = EnsureMethodBuilder(typeBuilder, methodName, MethodAttributes.Private | MethodAttributes.HideBySig, element.Mapping.TypeDesc.Type, new Type[1] { typeof(bool) });
2469 WriteSourceEnd(source, element.Mapping.TypeDesc.Type);
2470 }
2471 else if (element.Mapping is PrimitiveMapping)
2472 {
2473 bool flag = false;
2474 if (element.IsNullable)
2475 {
2476 MethodInfo method = typeof(XmlSerializationReader).GetMethod("ReadNull", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
2477 ilg.Ldarg(0);
2478 ilg.Call(method);
2479 ilg.If();
2481 if (element.Mapping.TypeDesc.IsValueType)
2482 {
2483 throw Globals.NotSupported("No such condition. PrimitiveMapping && IsNullable = String, XmlQualifiedName and never IsValueType");
2484 }
2485 ilg.Load(null);
2486 WriteSourceEnd(source, element.Mapping.TypeDesc.Type);
2487 ilg.Else();
2488 flag = true;
2489 }
2490 if (element.Default != null && element.Default != DBNull.Value && element.Mapping.TypeDesc.IsValueType)
2491 {
2492 MethodInfo method2 = typeof(XmlSerializationReader).GetMethod("get_Reader", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
2493 MethodInfo method3 = typeof(XmlReader).GetMethod("get_IsEmptyElement", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
2494 ilg.Ldarg(0);
2495 ilg.Call(method2);
2496 ilg.Call(method3);
2497 ilg.If();
2498 MethodInfo method4 = typeof(XmlReader).GetMethod("Skip", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
2499 ilg.Ldarg(0);
2500 ilg.Call(method2);
2501 ilg.Call(method4);
2502 ilg.Else();
2503 flag = true;
2504 }
2505 if (element.Mapping.TypeDesc.Type == typeof(TimeSpan) || element.Mapping.TypeDesc.Type == typeof(DateTimeOffset))
2506 {
2507 MethodInfo method5 = typeof(XmlSerializationReader).GetMethod("get_Reader", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
2508 MethodInfo method6 = typeof(XmlReader).GetMethod("get_IsEmptyElement", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
2509 ilg.Ldarg(0);
2510 ilg.Call(method5);
2511 ilg.Call(method6);
2512 ilg.If();
2514 MethodInfo method7 = typeof(XmlReader).GetMethod("Skip", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
2515 ilg.Ldarg(0);
2516 ilg.Call(method5);
2517 ilg.Call(method7);
2518 LocalBuilder tempLocal = ilg.GetTempLocal(element.Mapping.TypeDesc.Type);
2520 ilg.InitObj(element.Mapping.TypeDesc.Type);
2522 WriteSourceEnd(source, element.Mapping.TypeDesc.Type);
2523 ilg.Else();
2525 WritePrimitive(element.Mapping, "Reader.ReadElementString()");
2526 WriteSourceEnd(source, element.Mapping.TypeDesc.Type);
2527 ilg.EndIf();
2528 }
2529 else
2530 {
2532 if (element.Mapping.TypeDesc == base.QnameTypeDesc)
2533 {
2534 MethodInfo method8 = typeof(XmlSerializationReader).GetMethod("ReadElementQualifiedName", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
2535 ilg.Ldarg(0);
2536 ilg.Call(method8);
2537 }
2538 else
2539 {
2540 string formatterName = element.Mapping.TypeDesc.FormatterName;
2541 WritePrimitive(source: (!(formatterName == "ByteArrayBase64") && !(formatterName == "ByteArrayHex")) ? "Reader.ReadElementString()" : "false", mapping: element.Mapping);
2542 }
2543 WriteSourceEnd(source, element.Mapping.TypeDesc.Type);
2544 }
2545 if (flag)
2546 {
2547 ilg.EndIf();
2548 }
2549 }
2550 else if (element.Mapping is StructMapping)
2551 {
2552 TypeMapping mapping = element.Mapping;
2554 if (checkForNull)
2555 {
2556 MethodInfo method9 = typeof(XmlSerializationReader).GetMethod("get_Reader", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
2557 MethodInfo method10 = typeof(XmlReader).GetMethod("Skip", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
2559 ilg.Load(null);
2560 ilg.If(Cmp.EqualTo);
2561 ilg.Ldarg(0);
2562 ilg.Call(method9);
2563 ilg.Call(method10);
2564 ilg.Else();
2565 }
2567 List<Type> list = new List<Type>();
2568 ilg.Ldarg(0);
2569 if (mapping.TypeDesc.IsNullable)
2570 {
2571 ilg.Load(element.IsNullable);
2572 list.Add(typeof(bool));
2573 }
2574 ilg.Ldc(boolVar: true);
2575 list.Add(typeof(bool));
2578 WriteSourceEnd(source, mapping.TypeDesc.Type);
2579 if (checkForNull)
2580 {
2581 ilg.EndIf();
2582 }
2583 }
2584 else
2585 {
2586 if (!(element.Mapping is SpecialMapping))
2587 {
2589 }
2590 SpecialMapping specialMapping = (SpecialMapping)element.Mapping;
2591 switch (specialMapping.TypeDesc.Kind)
2592 {
2593 case TypeKind.Node:
2594 {
2595 bool flag3 = specialMapping.TypeDesc.FullName == typeof(XmlDocument).FullName;
2597 MethodInfo method13 = typeof(XmlSerializationReader).GetMethod(flag3 ? "ReadXmlDocument" : "ReadXmlNode", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, new Type[1] { typeof(bool) });
2598 ilg.Ldarg(0);
2599 ilg.Ldc(!element.Any);
2600 ilg.Call(method13);
2601 if (specialMapping.TypeDesc != null)
2602 {
2603 ilg.Castclass(specialMapping.TypeDesc.Type);
2604 }
2605 WriteSourceEnd(source, specialMapping.TypeDesc.Type);
2606 break;
2607 }
2608 case TypeKind.Serializable:
2609 {
2610 SerializableMapping serializableMapping = (SerializableMapping)element.Mapping;
2611 if (serializableMapping.DerivedMappings != null)
2612 {
2613 MethodInfo method11 = typeof(XmlSerializationReader).GetMethod("GetXsiType", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, Type.EmptyTypes);
2616 LocalBuilder localBuilder = ilg.DeclareOrGetLocal(typeof(XmlQualifiedName), "tser");
2617 ilg.Ldarg(0);
2618 ilg.Call(method11);
2621 ilg.Load(null);
2622 ilg.Ceq();
2623 ilg.Brtrue(label);
2624 WriteQNameEqual("tser", serializableMapping.XsiType.Name, serializableMapping.XsiType.Namespace);
2625 ilg.Br_S(label2);
2627 ilg.Ldc(boolVar: true);
2629 ilg.If();
2630 }
2633 MethodInfo method12 = typeof(XmlSerializationReader).GetMethod("ReadSerializable", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, (!flag2) ? new Type[1] { typeof(IXmlSerializable) } : new Type[2]
2634 {
2635 typeof(IXmlSerializable),
2636 typeof(bool)
2637 });
2638 ilg.Ldarg(0);
2639 base.RaCodeGen.ILGenForCreateInstance(ilg, serializableMapping.TypeDesc.Type, serializableMapping.TypeDesc.CannotNew, cast: false);
2640 if (serializableMapping.TypeDesc.CannotNew)
2641 {
2642 ilg.ConvertValue(typeof(object), typeof(IXmlSerializable));
2643 }
2644 if (flag2)
2645 {
2646 ilg.Ldc(boolVar: true);
2647 }
2648 ilg.Call(method12);
2649 if (serializableMapping.TypeDesc != null)
2650 {
2651 ilg.ConvertValue(typeof(IXmlSerializable), serializableMapping.TypeDesc.Type);
2652 }
2654 if (serializableMapping.DerivedMappings != null)
2655 {
2657 WriteUnknownNode("UnknownNode", "null", null, anyIfs: true);
2658 }
2659 break;
2660 }
2661 default:
2663 }
2664 }
2665 if (choice != null)
2666 {
2668 CodeIdentifier.CheckValidIdentifier(choice.MemberIds[elementIndex]);
2669 base.RaCodeGen.ILGenForEnumMember(ilg, choice.Mapping.TypeDesc.Type, choice.MemberIds[elementIndex]);
2670 WriteSourceEnd(choiceSource, choice.Mapping.TypeDesc.Type);
2671 }
2672 }
void Add(TKey key, TValue value)
static string XmlInternalError
Definition SR.cs:1812
Definition SR.cs:7
void ConvertValue(Type source, Type target)
LocalBuilder DeclareOrGetLocal(Type type, string name)
void Call(MethodInfo methodInfo)
void Stloc(Type type, string name)
void Ldloca(LocalBuilder localBuilder)
void Ldloc(LocalBuilder localBuilder)
XmlSerializationILGen(TypeScope[] scopes, string access, string className)
MethodBuilder EnsureMethodBuilder(TypeBuilder typeBuilder, string methodName, MethodAttributes attributes, Type returnType, Type[] parameterTypes)
void WriteDerivedSerializable(SerializableMapping head, SerializableMapping mapping, string source, bool isWrappedAny)
void WriteQNameEqual(string source, string name, string ns)
void WriteArray(string source, string arrayName, ArrayMapping arrayMapping, bool readOnly, bool isNullable, int fixupIndex, int elementIndex)
void WriteUnknownNode(string func, string node, ElementAccessor e, bool anyIfs)

References System.Xml.Serialization.Accessor.Any, System.Xml.Serialization.CodeIdentifier.CheckValidIdentifier(), System.Xml.Serialization.Accessor.Default, System.Xml.Dictionary, System.elementIndex, System.Type.EmptyTypes, System.Xml.Serialization.TypeDesc.FormatterName, System.Xml.Serialization.ElementAccessor.IsNullable, System.Xml.Serialization.TypeDesc.IsValueType, System.Xml.Serialization.XmlSerializationILGen.IsWildcard(), System.list, System.Xml.Serialization.Accessor.Mapping, System.Xml.Serialization.Globals.NotSupported(), System.source, System.Xml.Serialization.TypeDesc.Type, System.Xml.Serialization.TypeMapping.TypeDesc, System.DBNull.Value, and System.SR.XmlInternalError.

Referenced by System.Xml.Serialization.XmlSerializationReaderILGen.WriteMemberElementsElse(), System.Xml.Serialization.XmlSerializationReaderILGen.WriteMemberElementsIf(), and System.Xml.Serialization.XmlSerializationReaderILGen.WriteNullableMethod().