Esempio n. 1
0
        internal TypeDefinition(CharEnumerator chars)
        {
            if (chars == null)
            {
                throw new ArgumentException("Cannot parse null characters.");
            }

            StringBuilder sb = new StringBuilder();

            do
            {
                char c = chars.Current;

                if (TypeNameLexer.IsDefinitionCharacter(c))
                {
                    sb.Append(c);
                }
                else if (TypeNameLexer.IsDefinitionEnd(c))
                {
                    if (sb.Length == 0)
                    {
                        throw new InvalidOperationException(
                                  $"Could not parse type name, unexpected initial character {c}.");
                    }

                    if (sb[sb.Length - 1] == TypeNameLexer.BeginGeneric && c == TypeNameLexer.BraceGeneric)
                    {
                        sb.Remove(sb.Length - 1, 1);
                        PrecedesGeneric = true;
                    }

                    break;
                }
                else
                {
                    throw new InvalidOperationException(
                              $"Could not parse type name, terminated at: {sb}. Unexpected character {c}.");
                }
            }while (chars.MoveNext());

            name = sb.ToString();
        }
Esempio n. 2
0
 protected override Type ParseXName(XName xName) => ParseTypeName(TypeNameLexer.Parse(xName));