private XmlQueryType IntersectItemTypes(XmlQueryType left, XmlQueryType right) {
Debug.Assert(left.Count == 1 && left.IsSingleton, "left should be an item");
Debug.Assert(right.Count == 1 && right.IsSingleton, "right should be an item");
if (left.TypeCode == right.TypeCode && (left.NodeKinds & (XmlNodeKindFlags.Document | XmlNodeKindFlags.Element | XmlNodeKindFlags.Attribute)) != 0) {
if (left.TypeCode == XmlTypeCode.Node) {
return left;
}
// Intersect name tests
XmlQualifiedNameTest nameTest = left.NameTest.Intersect(right.NameTest);
// Intersect types
XmlSchemaType type = XmlSchemaType.IsDerivedFrom(left.SchemaType, right.SchemaType, /* exept:*/XmlSchemaDerivationMethod.Empty) ? left.SchemaType :
XmlSchemaType.IsDerivedFrom(right.SchemaType, left.SchemaType, /* exept:*/XmlSchemaDerivationMethod.Empty) ? right.SchemaType : null;
bool isNillable = left.IsNillable && right.IsNillable;
if ((object)nameTest == (object)left.NameTest && type == left.SchemaType && isNillable == left.IsNillable) {
// left is a subtype of right return left
return left;
}
else if ((object)nameTest == (object)right.NameTest && type == right.SchemaType && isNillable == right.IsNillable) {
// right is a subtype of left return right
return right;
}
else if (nameTest != null && type != null) {
// create a new type
return ItemType.Create(left.TypeCode, nameTest, type, isNillable);
}
}
else if (left.IsSubtypeOf(right)) {
// left is a subset of right, so left is in the intersection
return left;
}
else if (right.IsSubtypeOf(left)) {
// right is a subset of left, so right is in the intersection
return right;
}
return None;
}