【问题标题】:Adding TypeConverterAttribute at runtime does not result in correct TypeConverter在运行时添加 TypeConverterAttribute 不会导致正确的 TypeConverter
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-03-05
      • 2023-03-25
      • 2014-11-26
      • 2015-08-05
      • 2017-10-14
      • 2021-11-24
      • 2011-04-21
      • 1970-01-01
      • 2021-03-16
      相关资源
      最近更新 更多