You must Sign In to post a response.
  • Category: .NET

    Multiple Constraint Generic class pass as parameter

    Hi All,

    i am working on one vb.net migration project ..project has some core dll..core dlls are updated based on the update need to re-write wrapper class

    Existing dll code:

    public abstract class BusinessService : IPayload, IPayload2, IParserContext

    existing code

    Public Sub Execute(ByVal pBs As BusinessService, ByVal pExecuteMode As ExecuteModes)
    If pExecuteMode = ExecuteModes.AwaitAsynchronous Then
    Me.Execute(pBs, Me.AWAIT_TIME_IN_MILLISEC)
    Else
    mStartTime = Now()
    mBsExecuterHelper = New BsExecuterHelper
    mBsExecuterHelper.Execute(pBs, pExecuteMode)
    End If
    End Sub

    New Dll code:

    public class BusinessService<TRequest, TResponse> : IBusinessService where TRequest : BsRequest, new() where TResponse : BsResponse, new()
    {

    now i need to pass BusinessService as parameter to Existing code .i am struck here can anyone help me how to pass generic class as parameter with multiple constraint
  • #762827
    Hai Kumar,
    As you can see the new converted code:

    public class BusinessService<TRequest, TResponse> : IBusinessService where TRequest : BsRequest, new() where TResponse : BsResponse, new()
    {

    Where the class BusinessService is restricted to the types BsRequest and BsResponse, so it will take the input only of this type.
    You need to typecast your input parameters to these class type and then pass them.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #762828
    Hi pawan,
    how to pass BusinessService in this method.
    Public Sub Execute(ByVal pBs As BusinessService, ByVal pExecuteMode As ExecuteModes)
    If pExecuteMode = ExecuteModes.AwaitAsynchronous Then
    Me.Execute(pBs, Me.AWAIT_TIME_IN_MILLISEC)
    Else
    mStartTime = Now()
    mBsExecuterHelper = New BsExecuterHelper
    mBsExecuterHelper.Execute(pBs, pExecuteMode)
    End If
    End Sub


Sign In to post your comments