private void TypeSpec(TypeName typeName) { var @namespace = new List<string>(); while (true) { @namespace.Add(ReadUntil(".,+`[&*")); if (_nextChar != '.') { break; } Read('.'); } var typeNameList = @namespace; var nesting = new List<string>(); if (_nextChar == '+') { while (true) { nesting.Add(ReadUntil(",+`&*")); if (_nextChar != '+') { break; } Read('+'); } typeNameList = nesting; } typeName.Name = typeNameList[typeNameList.Count - 1]; typeNameList.RemoveAt(typeNameList.Count - 1); typeName.Namespace = new ReadOnlyCollection<string>(@namespace); typeName.Nesting = new ReadOnlyCollection<string>(nesting); while (_nextChar == '[') { typeName.Name += ReadUntil("]") + ']'; Read(']'); } if (_nextChar == '`') { Read('`'); var argCount = int.Parse(ReadUntil("["), CultureInfo.InvariantCulture); var typeArgs = new TypeName[argCount]; Read('['); for (var i = 0; i < argCount; ++i) { Read('['); typeArgs[i] = new TypeName(); TypeSpec(typeArgs[i]); if (i < argCount - 1) { ReadUntil("["); } else { Read(']'); } } typeName.TypeArguments = new ReadOnlyCollection<TypeName>(typeArgs); Read(']'); } else { typeName.TypeArguments = _emptyTypes; } if(_nextChar == '*') { Read('*'); typeName.IsPointer = true; } if (_nextChar == '&') { Read('&'); typeName.IsByRef = true; } if (_nextChar == ',') { IgnoreSpaces(); var assemblyName = ReadUntil("]"); typeName.AssemblyName = new AssemblyName(assemblyName); } }
public void Parse(string assemblyQualifiedName, TypeName typeName) { _reader = new StringReader(assemblyQualifiedName); Read(); TypeSpec(typeName); if (_nextChar != null) { throw new FormatException("There are remaining unparsed characters."); } }