internal static GenericTypeName?TryParse(string text)
        {
            if (text.IndexOf('[') is var index &&
                index > 0)
            {
                var metadataName = text.Substring(0, index);
                if (TryParseArity(metadataName, out var arity) &&
                    GenericTypeArgument.TryParseBracketedList(text, index, arity, out var typeArguments) &&
                    arity == typeArguments.Length)
                {
                    return(new GenericTypeName(metadataName, typeArguments));
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public static bool TryParse(string text, out GenericTypeName genericTypeName)
        {
            if (text.IndexOf('[') is var index &&
                index > 0)
            {
                var metadataName = text.Substring(0, index);
                if (TryParseArity(metadataName, out var arity) &&
                    GenericTypeArgument.TryParseBracketedList(text, index, arity, out var typeArguments) &&
                    arity == typeArguments.Length)
                {
                    genericTypeName = new GenericTypeName(metadataName, typeArguments);
                    return(true);
                }
            }

            genericTypeName = default(GenericTypeName);
            return(false);
        }
        private static bool TryParse(string text, ref int pos, out GenericTypeArgument genericTypeArgument)
        {
            while (pos < text.Length &&
                   (text[pos] == ' ' || text[pos] == ','))
            {
                pos++;
            }

            if (text[pos] == '[' &&
                TryFindBracketedList(text, pos, out var bracketed))
            {
                var temp = 1;
                if (TryParse(bracketed, ref temp, out genericTypeArgument))
                {
                    pos += bracketed.Length;
                    while (pos < text.Length &&
                           text[pos] == ' ')
                    {
                        pos++;
                    }

                    return(true);
                }
            }
            else if (TryFindMetadataName(text, ref pos, out var metadataName, out var arity))
            {
                if (arity > 0 &&
                    TryFindBracketedList(text, pos, out var argsString) &&
                    TryParseBracketedList(argsString, 0, arity, out var args))
                {
                    genericTypeArgument = new GenericTypeArgument(metadataName, args);
                    pos += argsString.Length;
                    return(true);
                }

                genericTypeArgument = new GenericTypeArgument(metadataName, null);
                return(true);
            }

            pos = int.MaxValue;
            genericTypeArgument = default(GenericTypeArgument);
            return(false);
        }