Пример #1
0
        /// <summary>
        /// Parses a .Net XML documentation parameter type name.
        /// </summary>
        public static DotNetParameter FromVisualStudioXml(string typeName)
        {
            ParameterCategory category = ParameterCategory.Normal;

            if (typeName.Contains("@"))
            {
                category = ParameterCategory.OutOrRef;
            }
            typeName = typeName.Replace("@", "");
            return(new DotNetParameter(DotNetQualifiedTypeName.FromVisualStudioXml(typeName), category));
        }
        /// <summary>
        /// Parses a .Net XML documentation type name.
        /// Not intended for type declarations. Intended for field types, property types, parameter types, and return types.
        /// </summary>
        public static new DotNetQualifiedTypeName FromVisualStudioXml(string typeName)
        {
            if (String.IsNullOrEmpty(typeName))
            {
                return(new DotNetQualifiedTypeName());
            }

            if (DotNetReferenceClassGeneric.HasExpectedVisualStudioXmlFormat(typeName))
            {
                return(DotNetReferenceClassGeneric.FromVisualStudioXml(typeName));
            }

            if (DotNetReferenceMethodGeneric.HasExpectedVisualStudioXmlFormat(typeName))
            {
                return(DotNetReferenceMethodGeneric.FromVisualStudioXml(typeName));
            }

            string[] dotDelimited  = typeName.SplitIgnoreNested('.');
            string   localName     = dotDelimited.Last();
            string   fullNamespace = (dotDelimited.Length == 1) ? null : String.Join(".", dotDelimited.Take(dotDelimited.Length - 1).ToArray());

            //fully qualified generic type parameters
            //such as System.Collections.Generic.List<T> which are formatted as System.Collections.Generic.List{`0}
            List <DotNetQualifiedTypeName> parameters = new List <DotNetQualifiedTypeName>();

            if (localName.EndsWith("}"))
            {
                string parameterSignature = localName.Substring(localName.IndexOf("{")).RemoveOuterBraces();
                localName  = localName.Substring(0, localName.IndexOf("{"));
                parameters = parameterSignature.SplitIgnoreNested(',').Select(p => DotNetQualifiedTypeName.FromVisualStudioXml(p)).ToList();
            }

            if (String.IsNullOrEmpty(fullNamespace))
            {
                return(new DotNetQualifiedTypeName(localName, parameters));
            }

            return(new DotNetQualifiedTypeName(localName, parameters, DotNetQualifiedTypeName.FromVisualStudioXml(fullNamespace)));
        }