帮助在 Excel PIA 程序集中使用 TypeConverters 进行枚举
我想使用 TypeCoverter 来区域化程序集中枚举的输出,该程序集是加载到 Excel 中的 PIA。
我可以运行它,并且它可以在我使用显式引用的程序集创建的测试项目中的程序集上运行,但是当运行已构建为 Excel PIA 的项目时。 如果我尝试: _ 公共枚举 MyEnum 项目A 项目B 结束枚举
并在代码中 myE = MyEnum.ItemA 昏暗转换器 As System.ComponentModel.TypeConverter = TypeDescriptor.GetConverter(myE)
在立即窗口中 ? converter.ToString() 规定 “System.ComponentModel.EnumConverter”
,而在我的其他项目(也是一个强签名的程序集,但直接从新创建的存根窗口表单项目引用)中,我得到
? 转换器.ToString “ClassLibrary1.LocalizedEnumConverter”
所以看起来 LocalizedEnumConverter 没有绑定到枚举 - 有什么想法吗? 这是因为 Excel 加载程序集的方式造成的吗?有没有办法解决这个问题?
I would like to use a TypeCoverter to regionalise output for enums in an assembly that is a PIA loaded into Excel.
I can run this and it works on an assembly in a test project I created with an explicitly referenceed assembly, however when running a project that has been built as an Excel PIA. If I try:
_
public enum MyEnum
ItemA
ItemB
end enum
and in code
myE = MyEnum.ItemA
Dim converter As System.ComponentModel.TypeConverter = TypeDescriptor.GetConverter(myE)
In the immediate window
? converter.ToString() goves
"System.ComponentModel.EnumConverter"
whereas in my other project (also a strongly signed assembly, but referenced directly from a newly created stub windows form project), I get
? converter.ToString
"ClassLibrary1.LocalizedEnumConverter"
so it look like the LocalizedEnumConverter is not being bound to the enum - any ideas? Is this because of the way Excel loads the assembly, and is there a way arounfd this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
类型转换器与枚举位于同一个 dll 中吗? TypeDescriptor 必须能够解析类型转换器、UI 类型编辑器等 - 否则它会使用简单的默认值。
我还没有对 Excel 进行任何具体的尝试,但我想知道它是否不像程序集解析那么简单...
如果有帮助,您可以使用
AppDomain.AssemblyResolve
事件来自定义程序集正在加载 - 但这是一个复杂的区域......除非绝对必要,否则我会避免它。Is the type converter in the same dll as the enum? TypeDescriptor must be able to resolve the type-converters, UI-type-editors, etc - otherwise it uses the simple defaults.
I haven't tried anything sepcifically with Excel, but I'm wondering if it isn't as simple as assembly resolution...
If it helps, you can use the
AppDomain.AssemblyResolve
event to customize assembly loading - but this is a complex area... I'd avoid it unless absolutely necessary.经过大量的挖掘后,我找到了解决方案,这适用于无法解析的程序集:
添加程序集解析的处理程序:
然后处理解析:
After a fair amount of digging around, I have found the solution, this will work for an assembly that is loaded by cannot be resolved:
Add a handler for the Assembly Resolution:
then to handle the resolution: