涉及泛型时,C#COM接口不可见 [英] C# COM interface not visible when genericity is involved

查看:74
本文介绍了涉及泛型时,C#COM接口不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个涉及很多COM的专业项目中工作,我们遇到以下问题:

I work on a professional project with a lot of COM involved, and we encounter the following issue:

使用以下代码:

[ComVisible(true)]
public interface IComFakeCall { }

[ComVisible(false)]
public class BaseClass<T> { }

[ComVisible(true)]
public class ComFakeCall : BaseClass<string>, IComFakeCall { }

接口IComFakeCall在Excel VBA编辑器中不可见.

the interface IComFakeCall is not visible from the Excel VBA editor.

如果我删除了通用性,则可见:

Whereas it is visible if I remove the genericity, like that :

[ComVisible(true)]
public interface IComFakeCall { }

[ComVisible(false)]
public class BaseClass { }

[ComVisible(true)]
public class ComFakeCall : BaseClass, IComFakeCall { }

为什么第一个示例中的界面不可见?

How come my interface from the first example isn't visible?

COM对象和通用类的继承是否存在已知问题?

Is there a known issue with COM objects and the inheritance of generic classes?

推荐答案

旧的COM系统没有以下概念:泛型*:

The old COM system has no concepts of generics*:

https://msdn.microsoft.com/en-us/library/ms229590(VS.80).aspx

http://stackoverflow.com/questions/1277741/com-interop-using-generic类型

http://stackoverflow .com/questions/7003844/why-is-it-that-arraylist-works-with-com-interop-but-ilistt-doesnt http://stackoverflow.com/questions/269581 /what-are-alternatives-to-generic-collections-for-com-interop

*事实上,这是.NET首先替换它的原因之一.

*Indeed that was one reason .NET is there to replace it in the first place!


这篇关于涉及泛型时,C#COM接口不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆