I have a dictionary of type parameter values:
ImmutableDictionary<string, ITypeSymbol> typeParameterValues;
How can with an ITypeSymbol I substitute those type parameters in:
Eg. List<T> -> List<string> (if T is string)
Eg. Dictionary<K, V>.ValueCollection -> Dictionary<string, int>.ValueCollection (if K is string and V is int)
So far I have been able to make the first example work with the following code:
static ITypeSymbol SubstituteGenericArgs (ITypeSymbol type) => type switch {
ITypeParameterSymbol tps => typeParameterValues[tps.Name]
INamedTypeSymbol nts when nts.IsGeneric => nts.ConstructedFrom.Construct(
nts.TypeParameters.Select(SubstituteGenericArgs).ToArray()
),
INamedTypeSymbol ngts when !ngts.IsGeneric => ngts
};
I know I can do nts.ContainingType but the problem is once I have substituted the correct type arguments into the containing type, there is no way to get the original type using the new containing type that I have found.