ReadOnly Property Inheritance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • James.R.Thigpen@gmail.com

    ReadOnly Property Inheritance

    I am trying to create a read-only interface for an object.

    Say I have a Part, which I want to Implement IReadOnlyPart.
    IReadOnlyPart will have

    ReadOnly Property PartNumber() As String

    And I *want* Part to have

    Public Property PartNumber() As String Implements
    IPart.PartNumbe r
    Get
    Return partNumberValue
    End Get
    Set(ByVal value As String)
    partNumberValue = value
    End Set
    End Property

    But that is a compile error "Error 72 'PartNumber' cannot implement
    'PartNumber' because there is no matching property on interface
    'IPart'."

    Is there any way to get this to work or is this simply not How Things
    Are Done.

    Thanks,

    James Thigpen
  • Herfried K. Wagner [MVP]

    #2
    Re: ReadOnly Property Inheritance

    <James.R.Thigpe n@gmail.comschr ieb:
    >I am trying to create a read-only interface for an object.
    >
    Say I have a Part, which I want to Implement IReadOnlyPart.
    IReadOnlyPart will have
    >
    ReadOnly Property PartNumber() As String
    >
    And I *want* Part to have
    >
    Public Property PartNumber() As String Implements
    IPart.PartNumbe r
    Get
    Return partNumberValue
    End Get
    Set(ByVal value As String)
    partNumberValue = value
    End Set
    End Property
    >
    But that is a compile error "Error 72 'PartNumber' cannot implement
    'PartNumber' because there is no matching property on interface
    'IPart'."
    >
    Is there any way to get this to work or is this simply not How Things
    Are Done.
    Unfortunately what you want to archieve is not supported by the VB compiler.
    You may want to implement the 'Set' part as a function instead ('Function
    SetPartNumber') .

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

    Comment

    • James.R.Thigpen@gmail.com

      #3
      Re: ReadOnly Property Inheritance

      Ok, Thanks. Does C# let you do this or is it a .net idiom?

      James

      On Feb 27, 12:18 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
      h...@gmx.atwrot e:
      <James.R.Thig.. .@gmail.comschr ieb:
      >
      >
      >
      I am trying to create a read-only interface for an object.
      >
      Say I have a Part, which I want to Implement IReadOnlyPart.
      IReadOnlyPart will have
      >
      ReadOnly Property PartNumber() As String
      >
      And I *want* Part to have
      >
      Public Property PartNumber() As String Implements
      IPart.PartNumbe r
      Get
      Return partNumberValue
      End Get
      Set(ByVal value As String)
      partNumberValue = value
      End Set
      End Property
      >
      But that is a compile error "Error 72 'PartNumber' cannot implement
      'PartNumber' because there is no matching property on interface
      'IPart'."
      >
      Is there any way to get this to work or is this simply not How Things
      Are Done.
      >
      Unfortunately what you want to archieve is not supported by the VB compiler.
      You may want to implement the 'Set' part as a function instead ('Function
      SetPartNumber') .
      >
      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

      Comment

      • rowe_newsgroups

        #4
        Re: ReadOnly Property Inheritance

        On Feb 27, 4:06 pm, James.R.Thig... @gmail.com wrote:
        Ok, Thanks. Does C# let you do this or is it a .net idiom?
        >
        James
        >
        On Feb 27, 12:18 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
        >
        h...@gmx.atwrot e:
        <James.R.Thig.. .@gmail.comschr ieb:
        >
        >I am trying to create a read-only interface for an object.
        >
        Say I have a Part, which I want to Implement IReadOnlyPart.
        IReadOnlyPart will have
        >
        ReadOnly Property PartNumber() As String
        >
        And I *want* Part to have
        >
        Public Property PartNumber() As String Implements
        IPart.PartNumbe r
        Get
        Return partNumberValue
        End Get
        Set(ByVal value As String)
        partNumberValue = value
        End Set
        End Property
        >
        But that is a compile error "Error 72 'PartNumber' cannot implement
        'PartNumber' because there is no matching property on interface
        'IPart'."
        >
        Is there any way to get this to work or is this simply not How Things
        Are Done.
        >
        Unfortunately what you want to archieve is not supported by the VB compiler.
        You may want to implement the 'Set' part as a function instead ('Function
        SetPartNumber') .
        >
        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
        It's a CLR thing so it's not just VB.

        Thanks,

        Seth Rowe [MVP]

        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: ReadOnly Property Inheritance

          Seth --

          "rowe_newsgroup s" <rowe_email@yah oo.comschrieb:
          >I am trying to create a read-only interface for an object.
          >>
          Say I have a Part, which I want to Implement IReadOnlyPart.
          IReadOnlyPart will have
          >>
          ReadOnly Property PartNumber() As String
          >>
          And I *want* Part to have
          >>
          Public Property PartNumber() As String Implements
          IPart.PartNumbe r
          Get
          Return partNumberValue
          End Get
          Set(ByVal value As String)
          partNumberValue = value
          End Set
          End Property
          >>
          But that is a compile error "Error 72 'PartNumber' cannot implement
          'PartNumber' because there is no matching property on interface
          'IPart'."
          >>
          Is there any way to get this to work or is this simply not How Things
          Are Done.
          >>
          Unfortunately what you want to archieve is not supported by the VB
          compiler.
          You may want to implement the 'Set' part as a function instead
          ('Function
          SetPartNumber') .
          >
          It's a CLR thing so it's not just VB.
          No, it's actually a VB limitation. C# lets you do it.

          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

          Comment

          Working...