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

◆ WriteElements()

void System.Xml.Serialization.XmlSerializationWriterILGen.WriteElements ( SourceInfo source,
string enumSource,
ElementAccessor[] elements,
TextAccessor text,
ChoiceIdentifierAccessor choice,
string arrayName,
bool writeAccessors,
bool isNullable )
inlineprivate

Definition at line 1318 of file XmlSerializationWriterILGen.cs.

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;
1344 ElementAccessor elementAccessor = null;
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;
1365 string enumName = text2 + ".@" + FindChoiceEnumValue(elementAccessor2, (EnumMapping)choice.Mapping, out 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();
1410 SourceInfo sourceInfo2 = source.CastTo(typeDesc);
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));
1429 ilg.IsInst(typeof(XmlElement));
1430 ilg.Load(null);
1431 ilg.Cne();
1432 ilg.AndIf();
1433 LocalBuilder localBuilder = ilg.DeclareLocal(typeof(XmlElement), "elem");
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 {
1452 value = text2 + ".@" + FindChoiceEnumValue(item, (EnumMapping)choice.Mapping, out var eValue2);
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 }
LocalBuilder DeclareLocal(Type type, string name)
void Call(MethodInfo methodInfo)
void Stloc(Type type, string name)
void Ldloc(LocalBuilder localBuilder)
string FindChoiceEnumValue(ElementAccessor element, EnumMapping choiceMapping, out object eValue)
void WriteChoiceTypeCheck(SourceInfo source, string fullTypeName, ChoiceIdentifierAccessor choice, string enumName, TypeDesc typeDesc)
void WriteElement(SourceInfo source, ElementAccessor element, string arrayName, bool writeAccessor)

References System.Collections.Generic.Dictionary< TKey, TValue >.Add(), System.Xml.Serialization.CodeGenerator.AndIf(), System.Any, System.Xml.Serialization.CodeGenerator.Bne(), System.Xml.Serialization.CodeGenerator.Br(), System.Xml.Serialization.CodeGenerator.Br_S(), System.Xml.Serialization.CodeGenerator.Brfalse(), System.Xml.Serialization.CodeGenerator.Call(), System.Xml.Serialization.CodeGenerator.Ceq(), System.Xml.Serialization.CodeGenerator.Cne(), System.Xml.Serialization.TypeDesc.CreateArrayTypeDesc(), System.Xml.Serialization.CodeGenerator.DeclareLocal(), System.Xml.Serialization.CodeGenerator.DefineLabel(), System.Xml.Dictionary, System.Xml.Serialization.CodeGenerator.Else(), System.Type.EmptyTypes, System.Xml.Serialization.CodeGenerator.EndIf(), System.Xml.Serialization.XmlSerializationWriterILGen.FindChoiceEnumValue(), System.Xml.Serialization.XmlSerializationILGen.GetCSharpString(), System.Xml.Serialization.CodeGenerator.If(), System.Xml.Serialization.XmlSerializationILGen.ilg, System.Xml.Serialization.XmlSerializationILGen.ILGenLoad(), System.Xml.Serialization.CodeGenerator.InitElseIf(), System.Xml.Serialization.CodeGenerator.InitIf(), System.Xml.Serialization.CodeGenerator.IsInst(), System.Xml.Serialization.ElementAccessor.IsUnbounded, System.item, System.Xml.Serialization.CodeGenerator.Ldarg(), System.Xml.Serialization.CodeGenerator.Ldc(), System.Xml.Serialization.CodeGenerator.Ldloc(), System.Xml.Serialization.CodeGenerator.Ldstr(), System.list, System.Xml.Serialization.CodeGenerator.Load(), System.Xml.Serialization.Accessor.Mapping, System.Xml.Serialization.CodeGenerator.MarkLabel(), System.source, System.Xml.Serialization.CodeGenerator.Stloc(), System.text, System.Xml.Serialization.CodeGenerator.Throw(), System.Xml.Serialization.TypeMapping.TypeDesc, System.value, System.Xml.Serialization.XmlSerializationWriterILGen.WriteChoiceTypeCheck(), System.Xml.Serialization.XmlSerializationWriterILGen.WriteElement(), System.Xml.Serialization.XmlSerializationWriterILGen.WriteInstanceOf(), and System.Xml.Serialization.XmlSerializationWriterILGen.WriteText().

Referenced by System.Xml.Serialization.XmlSerializationWriterILGen.WriteArrayItems(), and System.Xml.Serialization.XmlSerializationWriterILGen.WriteMember().