Implementing 2 Interfaces with 'Same Name' Properties

后端 未结 8 1976
天涯浪人
天涯浪人 2021-01-04 22:50

This seems like a reasonable (and maybe simple?) scenario, but how would you do the following:

Lets say I have 2 interfaces:

Interface ISimpleInterfa         


        
8条回答
  •  忘掉有多难
    2021-01-04 23:21

    The Implements keyword in VB.NET makes this easy:

    Public Interface ISimpleInterface
      ReadOnly Property ErrorMsg() As String
    End Interface
    
    Friend Interface IExtendedInterface
      Property ErrorMsg() As String
      Property SomeOtherProperty() As String
    End Interface
    
    Public Class Foo
      Implements ISimpleInterface, IExtendedInterface
      Private other As String
      Private msg As String
    
      Public Property ErrorMsgEx() As String Implements IExtendedInterface.ErrorMsg
        Get
          Return msg
        End Get
        Set(ByVal value As String)
          msg = value
        End Set
      End Property
    
      Public Property SomeOtherPropertyEx() As String Implements IExtendedInterface.SomeOtherProperty
        Get
          Return other
        End Get
        Set(ByVal value As String)
          other = value
        End Set
      End Property
    
      Public ReadOnly Property ErrorMsg() As String Implements ISimpleInterface.ErrorMsg
        Get
          Return msg
        End Get
      End Property
    End Class
    

提交回复
热议问题