Пример #1
0
        /// <summary>
        /// Transforms a type name specified in a given URN to a .Net-compatible type name.
        /// </summary>
        public string Parse(Uri uri)
        {
            if (!uri.Scheme.Equals("urn", StringComparison.OrdinalIgnoreCase))
            {
                throw new ArgumentException("A CodeFeatureId must be a URN", "uri");
            }

            string absolutePath = uri.AbsolutePath;

            const string featurePreamble = "feature:";
            const string contextPreamble = "context:";

            if (absolutePath.StartsWith(featurePreamble, StringComparison.OrdinalIgnoreCase))
            {
                absolutePath = absolutePath.Substring(featurePreamble.Length);
            }
            else if (absolutePath.StartsWith(contextPreamble, StringComparison.OrdinalIgnoreCase))
            {
                absolutePath = absolutePath.Substring(contextPreamble.Length);
            }

            // Workaround for a bug in .NET < 4.5.1 which incorrectly
            // escapes '[' and ']' as %5B and %5D (respectively) under some
            // circumstances, even though both are RFC 2396 unreserved characters.
            // http://stackoverflow.com/questions/20003106/uri-escapeuristring-with-square-braces
            // http://msdn.microsoft.com/en-us/library/hh367887%28v=vs.110%29.aspx
            absolutePath = absolutePath.Replace("%5B", "[").Replace("%5D", "]");

            var          root    = new TypeNameNode();
            TypeNameNode current = root;

            foreach (char c in absolutePath)
            {
                switch (c)
                {
                case '[':     // go one level down
                    var child = new TypeNameNode(current);
                    current.Children.Add(child);
                    current = child;
                    break;

                case ']':     // go one level up
                    current = current.Parent;
                    break;

                case ',':     // sibling will be caugth by '['
                case ' ':     // ignore whitespace
                    break;

                default:
                    current.ContentBuilder.Append(c);
                    break;
                }
            }

            root.Flatten();
            return(root.ToString());
        }
Пример #2
0
        /// <summary>
        /// Transforms a type name specified in a given URN to a .Net-compatible type name.
        /// </summary>
        public string Parse(Uri uri)
        {
            if (!uri.Scheme.Equals("urn", StringComparison.OrdinalIgnoreCase))
                throw new ArgumentException("A CodeFeatureId must be a URN", "uri");

            string absolutePath = uri.AbsolutePath;

            const string featurePreamble = "feature:";
            const string contextPreamble = "context:";
            if (absolutePath.StartsWith(featurePreamble, StringComparison.OrdinalIgnoreCase))
                absolutePath = absolutePath.Substring(featurePreamble.Length);
            else if (absolutePath.StartsWith(contextPreamble, StringComparison.OrdinalIgnoreCase))
                absolutePath = absolutePath.Substring(contextPreamble.Length);

            // Workaround for a bug in .NET < 4.5.1 which incorrectly
            // escapes '[' and ']' as %5B and %5D (respectively) under some
            // circumstances, even though both are RFC 2396 unreserved characters.
            // http://stackoverflow.com/questions/20003106/uri-escapeuristring-with-square-braces
            // http://msdn.microsoft.com/en-us/library/hh367887%28v=vs.110%29.aspx
            absolutePath = absolutePath.Replace("%5B", "[").Replace("%5D", "]");

            var root = new TypeNameNode();
            TypeNameNode current = root;

            foreach (char c in absolutePath)
            {
                switch (c)
                {
                    case '[': // go one level down
                        var child = new TypeNameNode(current);
                        current.Children.Add(child);
                        current = child;
                        break;
                    case ']': // go one level up
                        current = current.Parent;
                        break;
                    case ',': // sibling will be caugth by '['
                    case ' ': // ignore whitespace
                        break;
                    default:
                        current.ContentBuilder.Append(c);
                        break;
                }
            }

            root.Flatten();
            return root.ToString();
        }
Пример #3
0
            /// <summary>
            /// Transforms a type name specified in a given URN to a .Net-compatible type name.
            /// </summary>
            public static string Parse(string absolutePath)
            {
                const string preamble = "message:";

                if (absolutePath.StartsWith(preamble))
                {
                    absolutePath = absolutePath.Substring(preamble.Length);
                }

                // Workaround for a bug in .NET < 4.5.1 which incorrectly
                // escapes '[' and ']' as %5B and %5D (respectively) under some
                // circumstances, even though both are RFC 2396 unreserved characters.
                // http://stackoverflow.com/questions/20003106/uri-escapeuristring-with-square-braces
                // http://msdn.microsoft.com/en-us/library/hh367887%28v=vs.110%29.aspx
                absolutePath = absolutePath.Replace("%5B", "[").Replace("%5D", "]");

                TypeNameNode root    = new TypeNameNode();
                var          current = root;

                foreach (char c in absolutePath)
                {
                    switch (c)
                    {
                    case '[':     // go one level down
                        var child = new TypeNameNode {
                            Parent = current
                        };
                        current.Children.Add(child);
                        current = child;
                        break;

                    case ']':     // go one level up
                        current = current.Parent;
                        break;

                    case ',':     // sibling will be caugth by '['
                    case ' ':     // ignore whitespace
                        break;

                    default:
                        current.ContentBuilder.Append(c);
                        break;
                    }
                }

                root.Flatten();
                return(root.ToString());
            }