System.Xml.Xsl.Xslt.QilGenerator.MatchCountPattern C# (CSharp) Method

MatchCountPattern() private method

private MatchCountPattern ( QilNode countPattern, QilIterator testNode ) : QilNode
countPattern QilNode
testNode QilIterator
return QilNode
        private QilNode MatchCountPattern(QilNode countPattern, QilIterator testNode)
        {
            /*
                If the 'count' attribute is not specified, then it defaults to the pattern that matches any node
                with the same node kind as the context node and, if the context node has an expanded-QName, with
                the same expanded-QName as the context node.
            */
            if (countPattern != null)
            {
                return MatchPattern(countPattern, testNode);
            }
            else
            {
                QilNode current = GetCurrentNode();
                QilNode result;
                XmlNodeKindFlags nodeKinds = current.XmlType.NodeKinds;

                // If node kind is not known, invoke a runtime function
                if ((nodeKinds & (nodeKinds - 1)) != 0)
                {
                    return _f.InvokeIsSameNodeSort(testNode, current);
                }

                // Otherwise generate IsType check along with expanded QName check
                switch (nodeKinds)
                {
                    case XmlNodeKindFlags.Document: return _f.IsType(testNode, T.Document);
                    case XmlNodeKindFlags.Element: result = _f.IsType(testNode, T.Element); break;
                    case XmlNodeKindFlags.Attribute: result = _f.IsType(testNode, T.Attribute); break;
                    case XmlNodeKindFlags.Text: return _f.IsType(testNode, T.Text);
                    case XmlNodeKindFlags.Comment: return _f.IsType(testNode, T.Comment);
                    case XmlNodeKindFlags.PI: return _f.And(_f.IsType(testNode, T.PI), _f.Eq(_f.LocalNameOf(testNode), _f.LocalNameOf(current)));
                    case XmlNodeKindFlags.Namespace: return _f.And(_f.IsType(testNode, T.Namespace), _f.Eq(_f.LocalNameOf(testNode), _f.LocalNameOf(current)));
                    default:
                        Debug.Fail("Unexpected NodeKind: " + nodeKinds.ToString());
                        return _f.False();
                }

                // Elements and attributes have both local name and namespace URI
                return _f.And(result, _f.And(
                    _f.Eq(_f.LocalNameOf(testNode), _f.LocalNameOf(current)),
                    _f.Eq(_f.NamespaceUriOf(testNode), _f.NamespaceUriOf(GetCurrentNode()))
                ));
            }
        }
QilGenerator