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

◆ InstantiateTable()

DataTable System.Data.XSDSchema.InstantiateTable ( XmlSchemaElement node,
XmlSchemaComplexType typeNode,
bool isRef )
inlinepackage

Definition at line 1391 of file XSDSchema.cs.

1392 {
1395 string @namespace = node.QualifiedName.Namespace;
1396 DataTable dataTable = _ds.Tables.GetTable(XmlConvert.DecodeName(instanceName), @namespace);
1397 if (!FromInference || (FromInference && dataTable == null))
1398 {
1399 if (dataTable != null)
1400 {
1401 if (isRef)
1402 {
1403 return dataTable;
1404 }
1405 throw ExceptionBuilder.DuplicateDeclaration(instanceName);
1406 }
1407 if (isRef)
1408 {
1409 _refTables.Add(@namespace + ":" + instanceName);
1410 }
1411 dataTable = new DataTable(XmlConvert.DecodeName(instanceName));
1412 dataTable.TypeName = node.SchemaTypeName;
1413 dataTable.Namespace = @namespace;
1414 dataTable.Namespace = GetStringAttribute(node, "targetNamespace", @namespace);
1415 string stringAttribute = GetStringAttribute(typeNode, "CaseSensitive", "");
1416 if (stringAttribute.Length == 0)
1417 {
1418 stringAttribute = GetStringAttribute(node, "CaseSensitive", "");
1419 }
1420 if (0 < stringAttribute.Length)
1421 {
1422 if (stringAttribute == "true" || stringAttribute == "True")
1423 {
1425 }
1426 if (stringAttribute == "false" || stringAttribute == "False")
1427 {
1429 }
1430 }
1431 stringAttribute = GetMsdataAttribute(node, "Locale");
1432 if (stringAttribute != null)
1433 {
1434 if (0 < stringAttribute.Length)
1435 {
1437 }
1438 else
1439 {
1441 }
1442 }
1443 if (!FromInference)
1444 {
1445 dataTable.MinOccurs = node.MinOccurs;
1446 dataTable.MaxOccurs = node.MaxOccurs;
1447 }
1448 else
1449 {
1450 string prefix = GetPrefix(@namespace);
1451 if (prefix != null)
1452 {
1454 }
1455 }
1456 _ds.Tables.Add(dataTable);
1457 if (FromInference)
1458 {
1459 _tableDictionary.Add(dataTable, new List<DataTable>());
1460 }
1461 }
1462 HandleComplexType(typeNode, dataTable, arrayList, node.IsNillable);
1463 for (int i = 0; i < dataTable.Columns.Count; i++)
1464 {
1465 dataTable.Columns[i].SetOrdinalInternal(i);
1466 }
1467 SetProperties(dataTable, node.UnhandledAttributes);
1468 SetExtProperties(dataTable, node.UnhandledAttributes);
1469 if (_dsElement != null && _dsElement.Constraints != null)
1470 {
1471 foreach (XmlSchemaIdentityConstraint constraint in _dsElement.Constraints)
1472 {
1473 if (!(constraint is XmlSchemaKeyref) && GetTableName(constraint) == dataTable.TableName && (GetTableNamespace(constraint) == dataTable.Namespace || GetTableNamespace(constraint) == null))
1474 {
1475 HandleConstraint(constraint);
1476 }
1477 }
1478 }
1479 foreach (DataTable item in arrayList)
1480 {
1481 if (item != dataTable && dataTable.Namespace == item.Namespace)
1482 {
1483 item._tableNamespace = null;
1484 }
1485 if (_dsElement != null && _dsElement.Constraints != null)
1486 {
1487 foreach (XmlSchemaIdentityConstraint constraint2 in _dsElement.Constraints)
1488 {
1489 if (!(constraint2 is XmlSchemaKeyref xmlSchemaKeyref) || !GetBooleanAttribute(xmlSchemaKeyref, "IsNested", defVal: false) || !(GetTableName(xmlSchemaKeyref) == item.TableName))
1490 {
1491 continue;
1492 }
1493 if (item.DataSet.Tables.InternalIndexOf(item.TableName) < -1)
1494 {
1495 if (GetTableNamespace(xmlSchemaKeyref) == item.Namespace)
1496 {
1497 HandleKeyref(xmlSchemaKeyref);
1498 }
1499 }
1500 else
1501 {
1502 HandleKeyref(xmlSchemaKeyref);
1503 }
1504 }
1505 }
1506 DataRelation dataRelation = null;
1507 DataRelationCollection childRelations = dataTable.ChildRelations;
1508 for (int j = 0; j < childRelations.Count; j++)
1509 {
1510 if (childRelations[j].Nested && item == childRelations[j].ChildTable)
1511 {
1513 }
1514 }
1515 if (dataRelation != null)
1516 {
1517 continue;
1518 }
1519 DataColumn dataColumn2;
1520 if (FromInference)
1521 {
1522 int num = dataTable.UKColumnPositionForInference;
1523 if (num == -1)
1524 {
1525 foreach (DataColumn column in dataTable.Columns)
1526 {
1527 if (column.ColumnMapping == MappingType.Attribute)
1528 {
1529 num = column.Ordinal;
1530 break;
1531 }
1532 }
1533 }
1534 dataColumn2 = dataTable.AddUniqueKey(num);
1535 }
1536 else
1537 {
1538 dataColumn2 = dataTable.AddUniqueKey();
1539 }
1540 DataColumn dataColumn3 = item.AddForeignKey(dataColumn2);
1541 if (FromInference)
1542 {
1543 dataColumn3.Prefix = item.Prefix;
1544 }
1545 dataRelation = new DataRelation(dataTable.TableName + "_" + item.TableName, dataColumn2, dataColumn3, createConstraints: true);
1546 dataRelation.Nested = true;
1547 item.DataSet.Relations.Add(dataRelation);
1548 if (FromInference && dataRelation.Nested && _tableDictionary.ContainsKey(dataRelation.ParentTable))
1549 {
1550 _tableDictionary[dataRelation.ParentTable].Add(dataRelation.ChildTable);
1551 }
1552 }
1553 return dataTable;
1554 }
void Add(TKey key, TValue value)
string GetInstanceName(XmlSchemaAnnotated node)
static CultureInfo InvariantCulture
static ? string DecodeName(string? name)
Definition XmlConvert.cs:55

References System.Data.DataTableCollection.Add(), System.Collections.ArrayList.Add(), System.Collections.Generic.Dictionary< TKey, TValue >.Add(), System.Xml.Schema.XmlSchemaElement.Constraints, System.Collections.Generic.Dictionary< TKey, TValue >.ContainsKey(), System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.Xml.XmlConvert.DecodeName(), System.Xml.Dictionary, System.Data.ExceptionBuilder.DuplicateDeclaration(), System.Data.XSDSchema.GetInstanceName(), System.Data.DataTableCollection.GetTable(), System.Globalization.CultureInfo.InvariantCulture, System.item, System.prefix, and System.Data.DataSet.Tables.