private ChoiceType(List<XmlQueryType> members) {
Debug.Assert(members != null && members.Count != 1, "ChoiceType must contain a list with 0 or >1 types.");
this.members = members;
// Compute supertype of all member types
for (int i = 0; i < members.Count; i++) {
XmlQueryType t = members[i];
Debug.Assert(t.Cardinality == XmlQueryCardinality.One, "ChoiceType member types must be prime types.");
// Summarize the union of member types as a single type
if (this.code == XmlTypeCode.None) {
// None combined with member type is the member type
this.code = t.TypeCode;
this.schemaType = t.SchemaType;
}
else if (IsNode && t.IsNode) {
// Node combined with node is node
if (this.code == t.TypeCode) {
// Element or attribute combined with element or attribute can be summarized as element(*, XmlSchemaComplexType.AnyType) or attribute(*, DatatypeImplementation.AnySimpleType)
if (this.code == XmlTypeCode.Element)
this.schemaType = XmlSchemaComplexType.AnyType;
else if (this.code == XmlTypeCode.Attribute)
this.schemaType = DatatypeImplementation.AnySimpleType;
}
else {
this.code = XmlTypeCode.Node;
this.schemaType = null;
}
}
else if (IsAtomicValue && t.IsAtomicValue) {
// Atomic value combined with atomic value is atomic value
this.code = XmlTypeCode.AnyAtomicType;
this.schemaType = DatatypeImplementation.AnyAtomicType;
}
else {
// Else we'll summarize types as Item
this.code = XmlTypeCode.Item;
this.schemaType = null;
}
// Always track union of node kinds
this.nodeKinds |= t.NodeKinds;
}
}