예제 #1
0
        static ITypeReference ParseTypeName(string typeName, ref int pos)
        {
            string reflectionTypeName = typeName;

            if (pos == typeName.Length)
            {
                throw new ReflectionNameParseException(pos, "Unexpected end");
            }
            ITypeReference result;

            if (reflectionTypeName[pos] == '`')
            {
                // type parameter reference
                pos++;
                if (pos == reflectionTypeName.Length)
                {
                    throw new ReflectionNameParseException(pos, "Unexpected end");
                }
                if (reflectionTypeName[pos] == '`')
                {
                    // method type parameter reference
                    pos++;
                    int index = ReflectionHelper.ReadTypeParameterCount(reflectionTypeName, ref pos);
                    result = TypeParameterReference.Create(SymbolKind.Method, index);
                }
                else
                {
                    // class type parameter reference
                    int index = ReflectionHelper.ReadTypeParameterCount(reflectionTypeName, ref pos);
                    result = TypeParameterReference.Create(SymbolKind.TypeDefinition, index);
                }
            }
            else
            {
                // not a type parameter reference: read the actual type name
                List <ITypeReference> typeArguments = new List <ITypeReference>();
                int    typeParameterCount;
                string typeNameWithoutSuffix = ReadTypeName(typeName, ref pos, true, out typeParameterCount, typeArguments);
                result = new GetPotentiallyNestedClassTypeReference(typeNameWithoutSuffix, typeParameterCount);
                while (pos < typeName.Length && typeName[pos] == '.')
                {
                    pos++;
                    string nestedTypeName = ReadTypeName(typeName, ref pos, false, out typeParameterCount, typeArguments);
                    result = new NestedTypeReference(result, nestedTypeName, typeParameterCount);
                }
                if (typeArguments.Count > 0)
                {
                    result = new ParameterizedTypeReference(result, typeArguments);
                }
            }
            while (pos < typeName.Length)
            {
                switch (typeName[pos])
                {
                case '[':
                    int dimensions = 1;
                    do
                    {
                        pos++;
                        if (pos == typeName.Length)
                        {
                            throw new ReflectionNameParseException(pos, "Unexpected end");
                        }
                        if (typeName[pos] == ',')
                        {
                            dimensions++;
                        }
                    } while (typeName[pos] != ']');
                    result = new ArrayTypeReference(result, dimensions);
                    break;

                case '*':
                    result = new PointerTypeReference(result);
                    break;

                case '@':
                    result = new ByReferenceTypeReference(result);
                    break;

                default:
                    return(result);
                }
                pos++;
            }
            return(result);
        }
예제 #2
0
 static ITypeReference ParseTypeName(string typeName, ref int pos)
 {
     string reflectionTypeName = typeName;
     if (pos == typeName.Length)
         throw new ReflectionNameParseException(pos, "Unexpected end");
     ITypeReference result;
     if (reflectionTypeName[pos] == '`') {
         // type parameter reference
         pos++;
         if (pos == reflectionTypeName.Length)
             throw new ReflectionNameParseException(pos, "Unexpected end");
         if (reflectionTypeName[pos] == '`') {
             // method type parameter reference
             pos++;
             int index = ReflectionHelper.ReadTypeParameterCount(reflectionTypeName, ref pos);
             result = TypeParameterReference.Create(SymbolKind.Method, index);
         } else {
             // class type parameter reference
             int index = ReflectionHelper.ReadTypeParameterCount(reflectionTypeName, ref pos);
             result = TypeParameterReference.Create(SymbolKind.TypeDefinition, index);
         }
     } else {
         // not a type parameter reference: read the actual type name
         List<ITypeReference> typeArguments = new List<ITypeReference>();
         int typeParameterCount;
         string typeNameWithoutSuffix = ReadTypeName(typeName, ref pos, true, out typeParameterCount, typeArguments);
         result = new GetPotentiallyNestedClassTypeReference(typeNameWithoutSuffix, typeParameterCount);
         while (pos < typeName.Length && typeName[pos] == '.') {
             pos++;
             string nestedTypeName = ReadTypeName(typeName, ref pos, false, out typeParameterCount, typeArguments);
             result = new NestedTypeReference(result, nestedTypeName, typeParameterCount);
         }
         if (typeArguments.Count > 0) {
             result = new ParameterizedTypeReference(result, typeArguments);
         }
     }
     while (pos < typeName.Length) {
         switch (typeName[pos]) {
             case '[':
                 int dimensions = 1;
                 do {
                     pos++;
                     if (pos == typeName.Length)
                         throw new ReflectionNameParseException(pos, "Unexpected end");
                     if (typeName[pos] == ',')
                         dimensions++;
                 } while (typeName[pos] != ']');
                 result = new ArrayTypeReference(result, dimensions);
                 break;
             case '*':
                 result = new PointerTypeReference(result);
                 break;
             case '@':
                 result = new ByReferenceTypeReference(result);
                 break;
             default:
                 return result;
         }
         pos++;
     }
     return result;
 }