private TypeSymbol ResolveType(TypeReference type, TypeSymbol parentSymbol = null) { int arrayDimensions = 0; while (type is ArrayType arrayType) { arrayDimensions++; type = arrayType.ElementType; } GenericInstanceType genericType = type as GenericInstanceType; if (genericType != null) { type = genericType.ElementType; } string name = ProcessNestedTypeName(type); if (string.CompareOrdinal(name, MscorlibTypeNames.System_ValueType) == 0) { // Ignore this type - it is the base class for enums, and other primitive types // but we don't import it since it is not useful in script return(null); } TypeSymbol typeSymbol; if (type is GenericParameter genericParameter) { typeSymbol = new GenericParameterSymbol(genericParameter.Position, genericParameter.Name, genericParameter.Owner.GenericParameterType == GenericParameterType.Type, symbols.GlobalNamespace); if (parentSymbol != null) { ((GenericParameterSymbol)typeSymbol).Owner = parentSymbol; } } else { typeSymbol = (TypeSymbol)((ISymbolTable)symbols).FindSymbol(name, null, SymbolFilter.Types); if (typeSymbol == null) { //TODO: Improve this error and provide context as to what type is missing from where errorHandler.ReportMissingReferenceError(name); resolveError = true; } } if (genericType != null) { List <TypeSymbol> typeArgs = new List <TypeSymbol>(); foreach (TypeReference argTypeRef in genericType.GenericArguments) { TypeSymbol argType = ResolveType(argTypeRef, typeSymbol); typeArgs.Add(argType); } typeSymbol = symbols.CreateGenericTypeSymbol(typeSymbol, typeArgs); Debug.Assert(typeSymbol != null); } if (arrayDimensions != 0) { for (int i = 0; i < arrayDimensions; i++) { typeSymbol = symbols.CreateArrayTypeSymbol(typeSymbol); } } return(typeSymbol); }
private TypeSymbol ResolveType(TypeReference type) { int arrayDimensions = 0; while (type is ArrayType) { arrayDimensions++; type = ((ArrayType)type).ElementType; } GenericInstanceType genericType = type as GenericInstanceType; if (genericType != null) { type = genericType.ElementType; } string name = type.FullName; if (String.CompareOrdinal(name, "System.ValueType") == 0) { // Ignore this type - it is the base class for enums, and other primitive types // but we don't import it since it is not useful in script return(null); } TypeSymbol typeSymbol; GenericParameter genericParameter = type as GenericParameter; if (genericParameter != null) { typeSymbol = new GenericParameterSymbol(genericParameter.Position, genericParameter.Name, (genericParameter.Owner.GenericParameterType == GenericParameterType.Type), _symbols.GlobalNamespace); } else { typeSymbol = (TypeSymbol)((ISymbolTable)_symbols).FindSymbol(name, null, SymbolFilter.Types); if (typeSymbol == null) { _errorHandler.ReportError("Unable to resolve referenced type '" + name + "'. Make sure all needed assemblies have been explicitly referenced.", String.Empty); _resolveError = true; } } if (genericType != null) { List <TypeSymbol> typeArgs = new List <TypeSymbol>(); foreach (TypeReference argTypeRef in genericType.GenericArguments) { TypeSymbol argType = ResolveType(argTypeRef); typeArgs.Add(argType); } typeSymbol = _symbols.CreateGenericTypeSymbol(typeSymbol, typeArgs); Debug.Assert(typeSymbol != null); } if (arrayDimensions != 0) { for (int i = 0; i < arrayDimensions; i++) { typeSymbol = _symbols.CreateArrayTypeSymbol(typeSymbol); } } return(typeSymbol); }