locked
Encapsulation question - may not be possible RRS feed

  • Question

  • User-906361721 posted

    This is probably going to sound daft.  I'm inheriting one server control from another and I'd like if it's at all possible to hide a property in the child class that's declared public in the parent class.  Is this possible or am I having a moron moment?

    Friday, April 25, 2008 11:54 AM

Answers

  • User955742345 posted

    You can use the Shadows modifier, which will replace the other definition with the current one, e.g. you can change parameters, return types, and modifiers.

     

    Public Class Test
    
      Private m_IsATest As Boolean
    
      Public Property ThisIsATest() As Boolean
        Get
          Return m_IsATest
        End Get
        Set(ByVal value As Boolean)
          m_IsATest = value
        End Set
      End Property
    
    End Class
    
    
    Public Class TestVersionTwo : Inherits Test
    
      Private m_IsATest As Boolean
    
      Private Shadows Property ThisIsATest() As String
        Get
          Return Convert.ToString(m_IsATest)
        End Get
        Set(ByVal value As String)
          m_IsATest = Boolean.Parse(value)
        End Set
      End Property
    
    End Class
     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 25, 2008 1:40 PM