2

出于序列化/反序列化的目的,我想为位于外部编译程序集中的类型设置一个 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 基类。

4

1 回答 1

0

经过一些试验,结果证明该解决方案已经正确,但由于我的运行配置而无法正常工作。使用“正常”入口点时一切正常(我使用的是最新 ReSharper 版本的静态调试挂钩,请参阅http://blog.jetbrains.com/dotnet/2015/08/28/run-configurations-debug-任何静态方法在视觉工作室和更多/

于 2015-09-26T12:57:36.630 回答