Application Experience of VB.NET Generic Types

 

base class definition

Namespace result

    Public MustInherit Class result
        Public Sub New()

        End Sub

        Property msg As String
        Property success As Boolean
    End Class

End Namespace

  

Define the function implementation:

    Shared Function ResultT(Of T As Models.result.result)(msg As String) As T
        Dim rsp As T = Nothing
        Dim parser As Models.result.result = Nothing
        rsp.msg = msg
        rsp.success = False
        Return rsp
        'Return New API.Resultobj(Of T) With {.msg = msg, .success = False}
    End Function

  

Example of calling:

Return ResultT(Of Models.result.httputil)(msg)

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324644545&siteId=291194637