如何公开词典到COM Interop [英] How To Expose a DIctionary<> to COM Interop

查看:63
本文介绍了如何公开词典到COM Interop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个定义如下的接口:

I have an Interface that is defined something along these lines:

Interface foo
  {
  int someProperty {get; set;}
  Dictionary<string, object> Items;
  }

实现此接口的具体类需要为COM Interop注册。一切都会编译,程序集似乎都注册成功,但是随后尝试创建COM对象(例如从PowerShell)时,我得到了一个错误。

The concrete class that implements this interface needs to be registered for COM Interop. Everything compiles and the assemblies seem to register OK, but then when trying to create the COM object (e.g. from PowerShell) I get an error.

这似乎与我正在使用的通用Dictionary<>类。所以这是一个问题:

This seems to be related to the generic Dictionary<> class that I'm using. So here is the question:


  1. 甚至可以通过COM Interop公开通用集合吗?

  2. 如果是,那么如何完成?

  3. 如果不是,那么解决方法是什么?


推荐答案

我最终通过Google搜索来到了这里,哈哈,我应该猜想这将来自您。

I ended up here via a Google search and, ha ha, I should have guessed this would come from you.

据我所知,泛型不能通过COM与标准编组器一起编组。我所知道的是C#中的ArrayList变成了COM中的标准集合,可由VBScript,VB,JScript 5.x等使用。但是由于我们正在朝着一个共同的目标努力,所以我将继续以及其他一些聚合类型,看看会发生什么。

As far as I know generics can't be marshalled through COM with the standard marshallers. What I do know is that an ArrayList in C# turns into a "standard" collection in COM, usable by VBScript, VB, JScript 5.x, etc. But since we're working toward a common goal, I'm going to play with some other aggregate types and see what happens.

这篇关于如何公开词典到COM Interop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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