private static string ParseXPathString(XPathLexer lexer, XmlNamespaceManager namespaceManager, bool throwOnFailure)
        {
            int firstTokenChar = lexer.FirstTokenChar;

            if (lexer.MoveNext())
            {
                XPathToken    token   = lexer.Token;
                StringBuilder builder = new StringBuilder(ParseXPathString(lexer, namespaceManager, throwOnFailure));
                if (XPathTokenID.NameTest == token.TokenID)
                {
                    string prefix = token.Prefix;
                    if (!string.IsNullOrEmpty(prefix))
                    {
                        string str3 = namespaceManager.LookupNamespace(prefix);
                        if (!string.IsNullOrEmpty(str3))
                        {
                            builder = builder.Replace(prefix, str3, firstTokenChar, prefix.Length);
                        }
                        else if (throwOnFailure)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new IndexOutOfRangeException(System.ServiceModel.SR.GetString("ConfigXPathNamespacePrefixNotFound", new object[] { prefix })));
                        }
                    }
                }
                return(builder.ToString());
            }
            return(lexer.ConsumedSubstring());
        }
Esempio n. 2
0
        static string ParseXPathString(XPathLexer lexer, XmlNamespaceManager namespaceManager, bool throwOnFailure)
        {
            string retVal = String.Empty;

            int currentTokenStart = lexer.FirstTokenChar;

            if (lexer.MoveNext())
            {
                XPathToken    token       = lexer.Token;
                StringBuilder xPathString = new StringBuilder(XPathMessageFilterElementComparer.ParseXPathString(lexer, namespaceManager, throwOnFailure));

                if (XPathTokenID.NameTest == token.TokenID)
                {
                    string nsPrefix = token.Prefix;
                    if (!String.IsNullOrEmpty(nsPrefix))
                    {
                        string ns = namespaceManager.LookupNamespace(nsPrefix);
                        if (!String.IsNullOrEmpty(ns))
                        {
                            xPathString = xPathString.Replace(nsPrefix, ns, currentTokenStart, nsPrefix.Length);
                        }
                        else
                        {
                            if (throwOnFailure)
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new IndexOutOfRangeException(SR.GetString(SR.ConfigXPathNamespacePrefixNotFound, nsPrefix)));
                            }
                        }
                    }
                }

                retVal = xPathString.ToString();
            }
            else
            {
                retVal = lexer.ConsumedSubstring();
            }

            return(retVal);
        }