Home All Groups Group Topic Archive Search About

Implementing an interface?

Author
23 Aug 2006 1:18 AM
David Veeneman
I'm new to VB.NET, and I am translating an object model from C# to VB.NET,
and I have come across an odd problem implementing an interface.

The interface is a custom interface, IDrillDown, which declares one
read-only property with the following VB.NET signature:

Public ReadOnly Property ActiveText() As String

I have declared the interface in the class declaration, like this:

Public Class CustomerItem
    Implements IDrillDown

    ...

End Class

Later in the class, I implement the interface by by declaring my ActiveText
property:

Public ReadOnly Property ActiveText() As String
    Get
        Return Me.Name
    End Get
End Property

VB.NET is giving me a compile-time error, saying that the class must
implement the ActiveText property for the IDrillDown interface. Needless to
say, I am puzzled, since I have implemented the property with the signature
required by the interface.

Can anyone shed some light on this? Thanks.

--
David Veeneman
Foresight Systems

Author
23 Aug 2006 1:39 AM
Tom Shelton
David Veeneman domain is my last name wrote:
Show quoteHide quote
> I'm new to VB.NET, and I am translating an object model from C# to VB.NET,
> and I have come across an odd problem implementing an interface.
>
> The interface is a custom interface, IDrillDown, which declares one
> read-only property with the following VB.NET signature:
>
> Public ReadOnly Property ActiveText() As String
>
> I have declared the interface in the class declaration, like this:
>
> Public Class CustomerItem
>     Implements IDrillDown
>
>     ...
>
> End Class
>
> Later in the class, I implement the interface by by declaring my ActiveText
> property:
>
> Public ReadOnly Property ActiveText() As String
>     Get
>         Return Me.Name
>     End Get
> End Property
>
>
David -

Public ReadOnly Property ActiveText() As String Implements
IDrillDown.ActiveText
    Get
        Return Me.Name
    End Get
End Property

HTH,

--
Tom Shelton
Author
23 Aug 2006 12:23 PM
David Veeneman
Thanks, Tom!
Author
23 Aug 2006 12:38 PM
Phill W.
David Veeneman wrote:

> The interface is a custom interface, IDrillDown
> Public ReadOnly Property ActiveText() As String

> Public ReadOnly Property ActiveText() As String
>     Get
>         Return Me.Name
>     End Get
> End Property
>
> VB.NET is giving me a compile-time error, saying that the class must
> implement the ActiveText property for the IDrillDown interface.

You have created a method that can implement th Interface's property,
but you haven't told VB to connect to two.
Interface implementations are explicit, so you have to add the
"Implements [Interfacename].[MethodName]" clause.

It allows you to do funny things like this :

Private ReadOnly Property Message() As String _
    Implements I.ActiveText

Yes, that's a Private property, implementing a Public Interface property
with a totally /different/ name (but /same/ signature, otherwise).

HTH,
    Phill  W.