Ejemplo n.º 1
0
        public static NamespaceUri Create(string namespaceName)
        {
            if (string.IsNullOrEmpty(namespaceName))
            {
                throw Failure.NullOrEmptyString(nameof(namespaceName));
            }

            return(Parse(namespaceName));
        }
Ejemplo n.º 2
0
        static Exception _TryParse(string text, out SegmentSequence[] results2) {
            results2 = null;
            if (string.IsNullOrEmpty(text)) {
                return Failure.NullOrEmptyString(nameof(text));
            }

            List<SegmentSequence> results = new List<SegmentSequence>();

            foreach (string sub in text.Split(';')) {

                if (Path.IsPathRooted(sub) && NoSpecialChars(sub)) {
                    RootedSegmentSequence sequence = new RootedSegmentSequence(sub);
                    results.Add(sequence);

                } else {
                    IteratedSegmentSequence segments;
                    _TryParseList(sub, out segments);
                    results.Add(segments);
                }
            }

            results2 = results.ToArray();
            return null;
        }
Ejemplo n.º 3
0
        static Exception _TryParse(string text, IServiceProvider serviceProvider, out QualifiedName result)
        {
            serviceProvider = serviceProvider ?? ServiceProvider.Null;
            result          = null;

            if (string.IsNullOrEmpty(text))
            {
                throw Failure.NullOrEmptyString(nameof(text));
            }

            // Remove decorations:  [prefix:b] ==> prefix:b
            if (text[0] == '[' && text[text.Length - 1] == ']')
            {
                text = text.Substring(1, text.Length - 2);
            }
            else if (text[0] == '{')
            {
                int num = text.LastIndexOf('}');

                if ((num <= 1) || (num == (text.Length - 1)))
                {
                    return(Failure.NotParsable("text", typeof(QualifiedName)));
                }

                if (num - 1 == 0)
                {
                    // The default namespace is used (as in '{} expandedName')
                    result = NamespaceUri.Default.GetName(text.Trim());
                    return(null);
                }
                else
                {
                    // Some other namespace is used
                    string ns        = text.Substring(1, num - 1);
                    string localName = text.Substring(num + 1).Trim();

                    NamespaceUri nu = NamespaceUri._TryParse(ns, false);
                    if (nu == null)
                    {
                        return(Failure.NotParsable("text", typeof(QualifiedName)));
                    }
                    result = nu.GetName(localName);
                    return(null);
                }
            }

            if (!text.Contains(":"))
            {
                result = NamespaceUri.Default.GetName(text.Trim());
                return(null);
            }

            var resolver = (IXmlNamespaceResolver)serviceProvider.GetService(typeof(IXmlNamespaceResolver))
                           ?? XmlNamespaceResolver.Global;

            int index = text.IndexOf(':');

            string prefix = text.Substring(0, index);
            string name   = text.Substring(index + 1);
            string fullNs = resolver.LookupNamespace(prefix);

            if (fullNs != null)
            {
                result = QualifiedName.Create(fullNs, name);
                return(null);
            }
            return(Failure.NotParsable("text", typeof(QualifiedName), RuntimeFailure.CannotExpandPrefixNotFound(prefix)));
        }