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

◆ CheckAmbiguousChoice()

void System.Xml.Serialization.XmlReflectionImporter.CheckAmbiguousChoice ( XmlAttributes a,
Type accessorType,
string accessorName )
inlineprivate

Definition at line 2099 of file XmlReflectionImporter.cs.

2100 {
2101 Hashtable hashtable = new Hashtable();
2102 XmlElementAttributes xmlElements = a.XmlElements;
2103 if (xmlElements != null && xmlElements.Count >= 2 && a.XmlChoiceIdentifier == null)
2104 {
2105 for (int i = 0; i < xmlElements.Count; i++)
2106 {
2107 Type key = ((xmlElements[i].Type == null) ? accessorType : xmlElements[i].Type);
2108 if (hashtable.Contains(key))
2109 {
2110 throw new InvalidOperationException(System.SR.Format(System.SR.XmlChoiceIdentiferMissing, "XmlChoiceIdentifierAttribute", accessorName));
2111 }
2112 hashtable.Add(key, false);
2113 }
2114 }
2115 if (hashtable.Contains(typeof(XmlElement)) && a.XmlAnyElements.Count > 0)
2116 {
2117 throw new InvalidOperationException(System.SR.Format(System.SR.XmlChoiceIdentiferMissing, "XmlChoiceIdentifierAttribute", accessorName));
2118 }
2119 XmlArrayItemAttributes xmlArrayItems = a.XmlArrayItems;
2120 if (xmlArrayItems == null || xmlArrayItems.Count < 2)
2121 {
2122 return;
2123 }
2124 NameTable nameTable = new NameTable();
2125 for (int j = 0; j < xmlArrayItems.Count; j++)
2126 {
2127 Type type = ((xmlArrayItems[j].Type == null) ? accessorType : xmlArrayItems[j].Type);
2128 string ns = xmlArrayItems[j].NestingLevel.ToString(CultureInfo.InvariantCulture);
2129 XmlArrayItemAttribute xmlArrayItemAttribute = (XmlArrayItemAttribute)nameTable[type.FullName, ns];
2130 if (xmlArrayItemAttribute != null)
2131 {
2132 throw new InvalidOperationException(System.SR.Format(System.SR.XmlArrayItemAmbiguousTypes, accessorName, xmlArrayItemAttribute.ElementName, xmlArrayItems[j].ElementName, "XmlElementAttribute", "XmlChoiceIdentifierAttribute", accessorName));
2133 }
2134 nameTable[type.FullName, ns] = xmlArrayItems[j];
2135 }
2136 }
virtual bool Contains(object key)
Definition Hashtable.cs:719
virtual void Add(object key, object? value)
Definition Hashtable.cs:676
static CultureInfo InvariantCulture
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string XmlArrayItemAmbiguousTypes
Definition SR.cs:1660
static string XmlChoiceIdentiferMissing
Definition SR.cs:1652
Definition SR.cs:7

References System.Collections.Hashtable.Add(), System.Collections.Hashtable.Contains(), System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.Xml.Dictionary, System.SR.Format(), System.Globalization.CultureInfo.InvariantCulture, System.key, System.type, System.SR.XmlArrayItemAmbiguousTypes, and System.SR.XmlChoiceIdentiferMissing.

Referenced by System.Xml.Serialization.XmlReflectionImporter.ImportAccessorMapping().