I can get all type converters set explicitly in my code using attribute, but how do I get implicit type converters when using TypeDescriptor.GetConverter.
private static string? GetTypeConverter(Compilation compilation, IPropertySymbol propertySymbol)
{
var typeConverterAttribute = compilation.GetTypeByMetadataName("System.ComponentModel.TypeConverterAttribute");
if (typeConverterAttribute is null)
{
return null;
}
var propertySymbolTypeConverter = GetTypeConverter(propertySymbol, typeConverterAttribute);
if (propertySymbolTypeConverter is not null)
{
return propertySymbolTypeConverter;
}
var propertySymbolTypeTypeConverter = GetTypeConverter(propertySymbol.Type, typeConverterAttribute);
if (propertySymbolTypeTypeConverter is not null)
{
return propertySymbolTypeTypeConverter;
}
// TODO: This does not work as it uses reflection.
// var type = Type.GetType(propertySymbol.Type.ToDisplayString());
// if (type is not null)
// {
// return TypeDescriptor.GetConverter(type).ToString();
// }
return null;
}