views:

73

answers:

2

I'd like to have a Private or Protected "Setter" for a property that also happens to be an abstract (MustOverride). I'm porting some code from C# to VB and in C# this is pretty straight forward. In VB not so much (for me anyway).

Some code...

In C#...

public abstract class BaseClassWithAnAbstractProperty
{
    public abstract int AnAbstractIntegerProperty { get; protected set; }
}

public class Foo : BaseClassWithAnAbstractProperty
{
    private int _anAbstractIntegerPropertyField = 0;

    public override int AnAbstractIntegerProperty 
    {
        get { return _anAbstractIntegerPropertyField; }
        protected set { _anAbstractIntegerPropertyField = value; }
    }
}

In VB...

Public MustInherit Class BaseClassWithAnAbstractProperty

    Public MustOverride Property AnAbstractIntegerProperty() As Integer

End Class

Public Class Foo
    Inherits BaseClassWithAnAbstractProperty

    Private _anAbstractIntegerPropertyField As Integer


    Public Overrides Property AnAbstractIntegerProperty As Integer
        Get
            Return _anAbstractIntegerPropertyField 
        End Get
        Protected Set(ByVal value As Integer)
            _anAbstractIntegerPropertyField = value
        End Set
    End Property
End Class

The issue seems to be the inability to flesh-out the Get/Set specifics in the declaration.

Am I chasing a ghost?

+1  A: 

This one may help you:

Protected Set in VB.Net for a property defined in an interface

Leniel Macaferi
Yes that was helpful, also let me to one of the comments; “It's not currently supported by the language, nor will it in Visual Basic 10 (i.e. the version with Visual Studio 2010). There is a wishlist item for exactly this. Until then, workarounds such as that suggested by nobugz are the only option.” Thanks everyone. Dead horse here.
nullphonic
A: 

For the record, the closest VB translation would give you:

Public MustInherit Class BaseClassWithAnAbstractProperty

    Public ReadOnly MustOverride Property AnAbstractIntegerProperty() As Integer

End Class

This might work, but as I found out, VB doesn't support this for Interfaces, at least

Rowland Shaw
Yeah I just copy/pasted one of your comments actually. I'm going for the work around. Thanks
nullphonic