I am trying to implement a typed collection that is intended for use in .NET and COM (Windows Script Host).
MSDN states that it is necessary to implement IEnumerable to make the collection available to VB / VBS For Each:
[ComVisible] [Guid] interface IMyCollection : IEnumerable { new IEnumerator GetEnumerator();
This works fine in VBScript / JScript, but for the CLR / C # foreach statement this collection seems untyped.
I tried to make the collection interface strongly typed as follows. Now the collection works fine in C #, but causes an error in VB, since the _NewEnum method (with id (-4)) is missing in the TLB
[ComVisible] [Guid] interface IMyCollection : IEnumerable<IMyItem> { }
The following code works fine in VBScript, but again makes the build untyped for .NET clients:
[ComVisible] [Guid] interface IMyCollection : IEnumerable<IMyItem> { new IEnumerator GetEnumerator(); }
Also tried to implement _NewEnum manually, returning an object that implements System.Runtime.InteropServices.ComTypes.IEnumVARIANT , but without success. The method was exported to TLB using the tlbexp utility, but without the MIDL id attribute.
How can i solve this?
source share