/// <summary>
/// Maps a type involving generic parameters to the corresponding type after substituting concrete
/// arguments for generic parameters.
/// </summary>
/// <remarks>
/// If the source type is a generic parameter, it is mapped to the corresponding argument.
/// If the source type is an open generic type using any of the specified generic parameters, it
/// is mapped to a closed constructed type based on the specified arguments.
/// </remarks>
override public IType MapType(IType sourceType)
{
if (sourceType == _genericSource)
{
return(_constructedOwner as IType);
}
IGenericParameter gp = sourceType as IGenericParameter;
if (gp != null)
{
// Map type parameters declared on our source
if (_map.ContainsKey(gp))
{
return(_map[gp]);
}
// Map type parameters declared on members of our source (methods / nested types)
return(GenericsServices.GetGenericParameters(Map(gp.DeclaringEntity))[gp.GenericParameterPosition]);
}
// TODO: Map nested types
// GenericType[of T].NestedType => GenericType[of int].NestedType
return(base.MapType(sourceType));
}