private static void AddItemToChoice(List<XmlQueryType> accumulator, XmlQueryType itemType) {
Debug.Assert(itemType.IsSingleton, "All types should be prime.");
bool addToList = true;
for (int i = 0; i < accumulator.Count; i++) {
// If new prime is a subtype of existing prime, don't add it to the union
if (itemType.IsSubtypeOf(accumulator[i])) {
return;
}
// If new prime is a subtype of existing prime, then replace the existing prime with new prime
if (accumulator[i].IsSubtypeOf(itemType)) {
if (addToList) {
addToList = false;
accumulator[i] = itemType;
}
else {
accumulator.RemoveAt(i);
i --;
}
}
}
if (addToList) {
accumulator.Add(itemType);
}
}