VB.NET overloading & COM
-
Hi, I'm working on a VB.NET project and my objects should be reachable using COM. My problem is that these objects have overloaded methods, properties, which seems problematic. For example I have a collection class with two item properties:
Default Public ReadOnly Property Item(ByVal Key As String) As Object
andDefault Public ReadOnly Property Item(ByVal Index As Integer) As Object
When I try to use an object of this class in a COM only environment - like MS Word - there only one Item can be seen, and allways the first. So using the order above I can query collection items only by Key, when I change the order I can query only by Index. This problem does not occour under .NET. My question is: how to do VB.NET overriding, polymorphism to satisfy COM requirements? (K) -
Hi, I'm working on a VB.NET project and my objects should be reachable using COM. My problem is that these objects have overloaded methods, properties, which seems problematic. For example I have a collection class with two item properties:
Default Public ReadOnly Property Item(ByVal Key As String) As Object
andDefault Public ReadOnly Property Item(ByVal Index As Integer) As Object
When I try to use an object of this class in a COM only environment - like MS Word - there only one Item can be seen, and allways the first. So using the order above I can query collection items only by Key, when I change the order I can query only by Index. This problem does not occour under .NET. My question is: how to do VB.NET overriding, polymorphism to satisfy COM requirements? (K)COM can't expose overloaded methods through Automation - it's not part of the specification. The .NET Framework selects one of the method overloads to be exposed to COM. I think you can select a different overload to be exposed by using the
ComVisibleAttribute
attribute to hide the ones you don't want COM/Automation clients to see. The other alternative is to give each overload a unique name (removing the overloads).