【发布时间】:2015-09-26 20:57:36
【问题描述】:
出于序列化/反序列化的目的,我想为位于外部已编译程序集中的类型设置一个 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 基类。
【问题讨论】:
标签: c# attributes typeconverter typedescriptor