/// <summary> /// Return true if the type of every item in "seq" matches the xml type identified by "idxType". /// </summary> public bool MatchesXmlType(IList <XPathItem> seq, int indexType) { XmlQueryType typBase = GetXmlType(indexType); XmlQueryCardinality card = seq.Count switch { 0 => XmlQueryCardinality.Zero, 1 => XmlQueryCardinality.One, _ => XmlQueryCardinality.More, }; if (!(card <= typBase.Cardinality)) { return(false); } typBase = typBase.Prime; for (int i = 0; i < seq.Count; i++) { if (!CreateXmlType(seq[0]).IsSubtypeOf(typBase)) { return(false); } } return(true); }
//----------------------------------------------- // loops //----------------------------------------------- public XmlQueryType CheckLoop(QilLoop node) { CheckClass(node[0], typeof(QilIterator)); Check(node.Variable.NodeType == QilNodeType.For || node.Variable.NodeType == QilNodeType.Let, node, "Loop variable must be a For or Let iterator"); XmlQueryType bodyType = node.Body.XmlType; XmlQueryCardinality variableCard = node.Variable.NodeType == QilNodeType.Let ? XmlQueryCardinality.One : node.Variable.Binding.XmlType.Cardinality; // Loops do not preserve DocOrderDistinct return(XmlQueryTypeFactory.PrimeProduct(bodyType, variableCard * bodyType.Cardinality)); }
private XmlQueryType ParseType(string s) { if (s != null && s.Length > 0) { Match m = typeInfoRegex.Match(s); Debug.Assert(m.Success && m.Groups.Count == 4, "Malformed Type info"); XmlQueryCardinality qc = new XmlQueryCardinality(m.Groups[1].Value); bool strict = bool.Parse(m.Groups[3].Value); string[] codes = m.Groups[2].Value.Split('|'); XmlQueryType[] types = new XmlQueryType[codes.Length]; for (int i = 0; i < codes.Length; i++) { types[i] = XmlQueryTypeFactory.Type((XmlTypeCode)Enum.Parse(typeof(XmlTypeCode), codes[i]), strict); } return(XmlQueryTypeFactory.Product(XmlQueryTypeFactory.Choice(types), qc)); } return(null); }