2015-09-26 58 views
0

對於序列化/反序列化的目的,我想爲位於外部編譯程序集中的類型設置TypeConverter。在運行時添加TypeConverterAttribute不會導致正確的TypeConverter

我偶然發現了這個問題,但所提供的解決方案似乎並沒有爲我工作: Add TypeConverter attribute to enum in runtime

TypeDescriptor.AddAttributes(typeof(ExternalType), 
new TypeConverterAttribute(typeof(ExternalTypeTypeConverter))); 

調用

TypeDescriptor.GetAttributes(typeof(ExternalType)); 

收益預期的屬性,但調用

TypeDescriptor.GetConverter(typeof(ExternalType)); 

不返回previo我們添加了轉換器,但只是TypeConverter基類。

回答

相關問題