出于序列化/反序列化的目的,我想为位于外部编译程序集中的类型设置一个 TypeConverter。
我偶然发现了这个问题,但提供的解决方案似乎对我不起作用: Add TypeConverter attribute to enum in runtime
TypeDescriptor.AddAttributes(typeof(ExternalType),
new TypeConverterAttribute(typeof(ExternalTypeTypeConverter)));
打电话
TypeDescriptor.GetAttributes(typeof(ExternalType));
按预期返回属性,但调用
TypeDescriptor.GetConverter(typeof(ExternalType));
不返回先前添加的转换器,而只返回 TypeConverter 基类。