private void AddConversionsForOneType(Type type)
{
if (type.GetTypeInfo().IsGenericType)
{
type = type.GetTypeInfo().GetGenericTypeDefinition();
}
if (_typesWithConversionsLoaded.Contains(type))
{
return;
}
_typesWithConversionsLoaded.Add(type);
// Always make the aggregate for the type, regardless of whether or not
// there are any conversions.
CType t = GetCTypeFromType(type);
if (!t.IsAggregateType())
{
CType endT;
while ((endT = t.GetBaseOrParameterOrElementType()) != null)
{
t = endT;
}
}
if (t.IsTypeParameterType())
{
// Add conversions for the bounds.
foreach (CType bound in t.AsTypeParameterType().GetBounds().ToArray())
{
AddConversionsForType(bound.AssociatedSystemType);
}
return;
}
Debug.Assert(t is AggregateType);
AggregateSymbol aggregate = t.AsAggregateType().getAggregate();
// Now find all the conversions and make them.
IEnumerable<MethodInfo> conversions = Enumerable.Where(type.GetRuntimeMethods(),
conversion => (conversion.IsPublic && conversion.IsStatic)
&& (conversion.Name == SpecialNames.ImplicitConversion || conversion.Name == SpecialNames.ExplicitConversion)
&& conversion.DeclaringType == type
&& conversion.IsSpecialName
&& !conversion.IsGenericMethod);
foreach (MethodInfo conversion in conversions)
{
MethodSymbol method = AddMethodToSymbolTable(
conversion,
aggregate,
conversion.Name == SpecialNames.ImplicitConversion ?
MethodKindEnum.ImplicitConv :
MethodKindEnum.ExplicitConv);
}
}
#endregion