/// <summary> /// Return all of the type parameters in this type and enclosing types, /// from outer-most to inner-most type. /// </summary> internal static ImmutableArray <TypeParameterSymbol> GetAllTypeParameters(this NamedTypeSymbol type) { // Avoid allocating a builder in the common case. if ((object)type.ContainingType == null) { return(type.TypeParameters); } var builder = ArrayBuilder <TypeParameterSymbol> .GetInstance(); type.GetAllTypeParameters(builder); return(builder.ToImmutableAndFree()); }
/// <summary> /// Return the nearest type parameter with the given name in /// this type or any enclosing type. /// </summary> internal static TypeParameterSymbol FindEnclosingTypeParameter(this NamedTypeSymbol type, string name) { var allTypeParameters = ArrayBuilder <TypeParameterSymbol> .GetInstance(); type.GetAllTypeParameters(allTypeParameters); TypeParameterSymbol result = null; foreach (TypeParameterSymbol tpEnclosing in allTypeParameters) { if (name == tpEnclosing.Name) { result = tpEnclosing; break; } } allTypeParameters.Free(); return(result); }
/// <summary> /// Returns a constructed type given the type it is constructed from and type arguments for its enclosing types and itself. /// </summary> /// <param name="typeArguments">the type arguments that will replace the type parameters, starting with those for enclosing types</param> /// <returns></returns> private static NamedTypeSymbol DeepConstruct(NamedTypeSymbol type, ImmutableArray<TypeSymbol> typeArguments) { Assert.True(type.IsDefinition); var allTypeParameters = ArrayBuilder<TypeParameterSymbol>.GetInstance(); type.GetAllTypeParameters(allTypeParameters); return new TypeMap(allTypeParameters.ToImmutableAndFree(), typeArguments).SubstituteNamedType(type); }