Home > Net >  Define an interface that requires a function that returns a class object that implements another int
Define an interface that requires a function that returns a class object that implements another int

Time:01-27

Hello and thank you in advance for your time.

I am running into an issue with some inheritance and interface implementation. Simplified code samples below for reference.

Problem: I am receiving a message from intellisense that `'Send' cannot implement 'Send' because there is no matching Function on interface 'IRequest'.

Goal: I want to implement Send like so: Public Async Function Send() As Task(of TR.Response) while including it as a requirement when implementing IRoute.

I've tried various combinations of implementations and done a good deal of reading but don't seem to be able to get around it and can't quite phrase my question well enough to find other similar situations.

Namespace BM
    Interface IRoute

        Interface IRequest
            ReadOnly Property SyncUrl As String
            ReadOnly Property AsyncUrl As String
            Function Send() As Task(of IResponse)
        End Interface

        Interface IResponse
        End Interface

    End Interface
End Namespace
Namespace BM
    Public Class TR : Implements IRoute

        Public Class Request : Implements IRoute.IRequest

            Public ReadOnly Property SyncUrl As String = "someString" Implements IRoute.IRequest.SyncUrl
            Private ReadOnly Property AsyncUrl As String = "someOtherString" Implements IRoute.IRequest.AsyncUrl

            Public Async Function Send() As Task(of TR.Response) Implements IRoute.IRequest.Send
            'do stuff in here
        End Function
        End Class

        Public Class Response : Inherits Response(Of TRResource)

            Public Class TRResource
            End Class
        End Class
    End Class
End NameSpace
Namespace BM
    Partial Public MustInherit Class Response(Of T) : Implements IRoute.IResponse
    End Class

    Public Class ResourceSet(Of T)
    End Class
End Namespace

CodePudding user response:

Firstly I would highly recommend not having Interfaces within Interfaces. Also the TR doesn't need to implement IRoute as there no properties, methods, and events in it to implement

The reason it doesn't like Send is because the IRequest interface uses Of IRoute.IResponse and the method uses Of TR.Response so it doesn't recognize it. They need to match.

  • Related