Properties: Catch 22

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pbd22

    #1

    Properties: Catch 22

    Hi. I am caught between 2 errors.

    When I have:

    Public Property Subtitle() As String
    Get
    Return _subTitle
    End Get
    Set(ByVal value As String)
    _subTitle = value
    End Set
    End Property



    I get:

    Error 21 Class 'WebPartBase' must implement 'ReadOnly Property
    Subtitle() As String' for interface
    'System.Web.UI. WebControls.Web Parts.IWebPart' . Implementing property
    must have matching 'ReadOnly' or 'WriteOnly' specifiers.


    And, when I have:

    Public ReadOnly Property Subtitle() As String
    Get
    Return _subTitle
    End Get
    End Property

    Public WriteOnly Property Subtitle() As String
    Set(ByVal value As String)
    _subTitle = Value
    End Set
    End Property



    I get:

    Quote:
    Error 22 'Public ReadOnly Property Subtitle() As String' and 'Public
    WriteOnly Property Subtitle() As String' cannot overload each other
    because they differ only by 'ReadOnly' or 'WriteOnly'.


    help?

  • Branco Medeiros

    #2
    Re: Properties: Catch 22

    pbd22 wrote:
    <snip>
    When I have:
    >
    Public Property Subtitle() As String
    Get
    Return _subTitle
    End Get
    Set(ByVal value As String)
    _subTitle = value
    End Set
    End Property
    >
    I get:
    >
    Error 21 Class 'WebPartBase' must implement 'ReadOnly Property
    Subtitle() As String' for interface
    'System.Web.UI. WebControls.Web Parts.IWebPart' . Implementing property
    must have matching 'ReadOnly' or 'WriteOnly' specifiers.
    <snip>

    The implementing method doesn't need to be named after the implemented
    one. Therefore, you can have:
    Public Property Subtitle() As String
    Get
    Return _subTitle
    End Get
    Set(ByVal value As String)
    _subTitle = value
    End Set
    End Property
    Private ReadOnly Property IWebPart_SubTit le As String _
    Implements System.Web.UI.W ebControls._
    WebParts.IWebPa rt.SubTitle
    Return Subtitle
    End Property


    HTH.

    Regards,

    Branco

    Comment

    • Pritcham

      #3
      Re: Properties: Catch 22

      On 19 Apr, 00:26, pbd22 <dush...@gmail. comwrote:
      Hi. I am caught between 2 errors.
      >
      When I have:
      >
      Public Property Subtitle() As String
      Get
      Return _subTitle
      End Get
      Set(ByVal value As String)
      _subTitle = value
      End Set
      End Property
      >
      I get:
      >
      Error 21 Class 'WebPartBase' must implement 'ReadOnly Property
      Subtitle() As String' for interface
      'System.Web.UI. WebControls.Web Parts.IWebPart' . Implementing property
      must have matching 'ReadOnly' or 'WriteOnly' specifiers.
      >
      And, when I have:
      >
      Public ReadOnly Property Subtitle() As String
      Get
      Return _subTitle
      End Get
      End Property
      >
      Public WriteOnly Property Subtitle() As String
      Set(ByVal value As String)
      _subTitle = Value
      End Set
      End Property
      >
      I get:
      >
      Quote:
      Error 22 'Public ReadOnly Property Subtitle() As String' and 'Public
      WriteOnly Property Subtitle() As String' cannot overload each other
      because they differ only by 'ReadOnly' or 'WriteOnly'.
      >
      help?
      Hi

      Just for your future reference, the error message you were getting
      tells you all you need to know - i.e.
      The first part ("Error 21 Class 'WebPartBase' must implement 'ReadOnly
      Property
      Subtitle() As String' for interface
      'System.Web.UI. WebControls.Web Parts.IWebPart' . "

      is telling you that you need to implement the ReadOnly Property
      SubTitle().

      The second part ("Implementi ng property must have matching 'ReadOnly'
      or 'WriteOnly' specifiers.") is a more generic message telling you
      that you have a mismatched property so you need to match it.

      Hope that helps
      Martin

      Comment

      • Chris Dunaway

        #4
        Re: Properties: Catch 22

        On Apr 18, 6:26 pm, pbd22 <dush...@gmail. comwrote:
        Hi. I am caught between 2 errors.
        >
        When I have:
        >
        Public Property Subtitle() As String
        Get
        Return _subTitle
        End Get
        Set(ByVal value As String)
        _subTitle = value
        End Set
        End Property
        >
        I get:
        >
        Error 21 Class 'WebPartBase' must implement 'ReadOnly Property
        Subtitle() As String' for interface
        'System.Web.UI. WebControls.Web Parts.IWebPart' . Implementing property
        must have matching 'ReadOnly' or 'WriteOnly' specifiers.
        >
        And, when I have:
        >
        Public ReadOnly Property Subtitle() As String
        Get
        Return _subTitle
        End Get
        End Property
        <snip>
        help?
        The Subtitle property on the IWebPart interface is just a read only
        property. Just get rid of the WriteOnly property, you don't need
        it.

        Chris

        Comment

        • pbd22

          #5
          Re: Properties: Catch 22

          On Apr 19, 8:56 am, Chris Dunaway <dunaw...@gmail .comwrote:
          On Apr 18, 6:26 pm, pbd22 <dush...@gmail. comwrote:
          >
          >
          >
          Hi. I am caught between 2 errors.
          >
          When I have:
          >
          Public Property Subtitle() As String
          Get
          Return _subTitle
          End Get
          Set(ByVal value As String)
          _subTitle = value
          End Set
          End Property
          >
          I get:
          >
          Error 21 Class 'WebPartBase' must implement 'ReadOnly Property
          Subtitle() As String' for interface
          'System.Web.UI. WebControls.Web Parts.IWebPart' . Implementing property
          must have matching 'ReadOnly' or 'WriteOnly' specifiers.
          >
          And, when I have:
          >
          Public ReadOnly Property Subtitle() As String
          Get
          Return _subTitle
          End Get
          End Property
          >
          <snip>
          >
          help?
          >
          The Subtitle property on the IWebPart interface is just a read only
          property. Just get rid of the WriteOnly property, you don't need
          it.
          >
          Chris

          Thanks all, much appreciated.

          Comment

          Working...