COM enumerable

Fabrice Lambert
Fabrice Lambert used Ask the Experts™
on
I'm writing a COM component, basically an enumerable class (so I can use the for .. each loop from VBA).

I managed to write the Following wich work:
<ComClass(FieldValidators.ClassId, FieldValidators.InterfaceId, FieldValidators.EventsId)>
Public Class FieldValidators
    Implements IEnumerable

#Region "GUID COM"
    Public Const ClassId As String = "2d368af9-55a7-4cca-a79d-06b6c3a91554"
    Public Const InterfaceId As String = "5094acfa-2799-491d-b7f0-ebc4a2d0e755"
    Public Const EventsId As String = "a31bb5c3-99c6-4548-85cc-fbe83d407867"
#End Region

    Private mFieldValidators As List(Of IFieldValidator)

    Public Sub New()
        MyBase.New()
        mFieldValidators = New List(Of IFieldValidator)
    End Sub

    Protected Overrides Sub Finalize()
        mFieldValidators = Nothing
        MyBase.Finalize()
    End Sub

    Public Sub Add(ByRef validator As IFieldValidator)
        mFieldValidators.Add(validator)
    End Sub

    Public Function Count() As Long
        Count = mFieldValidators.Count
    End Function

    Public Iterator Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
        For Each fieldValidator In mFieldValidators
            Yield fieldValidator
        Next
    End Function

    Default Public ReadOnly Property item(ByVal index As ULong) As IFieldValidator
        Get
            item = mFieldValidators(index)
        End Get
    End Property
End Class

Open in new window

But the resulting enumerator is poorly typed (IEnumVARIANT), I would like to return objects of type IFieldValidator.

Is it doable ?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ste5anSenior Developer

Commented:
Did you publish IFieldValidator?
Fabrice LambertConsulting
Distinguished Expert 2017

Author

Commented:
Yeah, it is an interface (as the name suggest it).

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial