Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net error: Implementing property must have matching 'ReadOnly' or 'WriteOnly' specifiers

I'm getting this error when trying to implement an interface in vb.net:

Public Interface IFoo
   ReadOnly Property Foo() As String
End Interface

Public Class myFoo
  Implements IFoo

  Public ReadOnly Property Foo() As String
     Get
       return "Foo"
     End Get
  End Property
...
End Class

What is missing?

like image 220
chris Avatar asked Mar 09 '11 17:03

chris


1 Answers

You will want to tell the code that the myFoo.Foo implements the IFoo.Foo (notice the added Implements IFoo.Foo):

Public Interface IFoo
    ReadOnly Property Foo() As String
End Interface

Public Class myFoo
    Implements IFoo

    Public ReadOnly Property Foo() As String Implements IFoo.Foo
        Get
            Return "Foo"
        End Get
    End Property
End Class

As far as I know, VB.NET does not support implicit interface implementations in the same way as C# does.

like image 164
Fredrik Mörk Avatar answered Sep 18 '22 19:09

Fredrik Mörk