我在 Net 中编写了一个类 dll,在迁移应用程序时必须将其公开给 VB6。此要求是临时的,因此我希望在 Net dll 中的方法调用和返回值中使用的类型上做出尽可能少的让步。该 dll 大量使用 IEnumerable>、List>、Dictionary> 等。和 SortedDictionary>作为参数和返回值。在哪里可以找到如何在 Com 和 Net 之间编组这些集合?
I have written a class dll in Net that I have to expose to VB6 while we are migrating our application. This requirement is temporary so I want to make as little concessions as possible in the types that are used in the method calls and return values in the Net dll. The dll makes heavy use of IEnumerable<T
>, List<T
>, Dictionary<TKey,TValue
> and SortedDictionary<TKey,TValue
> as parameters and return values. Where can I find how to marshall these collections between Com and Net?
发布评论
评论(1)
VB6 可以枚举任何实现
IEnumerable
的对象。IEnumerable
接口不会导出到 COM,因为它不支持泛型,但您可以返回完全相同的枚举器对象。在 VB6 方面,只需使用通常的
For Each X In Y
循环即可。VB6 can enumerate any object that implements
IEnumerable
.IEnumerable<T>
interfaces are not exported to COM as it doesn't support generics, but you can return exactly the same enumerator object.On the VB6 side, just use the usual
For Each X In Y
loop.