Private or secure set for MustOverride property

I would like to have a private or protected "Setter" for a property that is also abstract (MustOverride). I port the code from C # to VB, and in C # it is pretty straight forward. There is not much in VB (for me, anyway).

Some codes ...

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

It seems that the problem is the inability to reflect the specifics of Get / Set in the declaration.

Am I chasing a ghost?

+3
source share
1 answer

For recording, the nearest VB translation will give you:

Public MustInherit Class BaseClassWithAnAbstractProperty

    Public ReadOnly MustOverride Property AnAbstractIntegerProperty() As Integer

End Class

This may work, but as I found out , VB does not support this for interfaces, at least

+2
source

Source: https://habr.com/ru/post/1756368/


All Articles