". No implicit link I am trying to create a...">

The type cannot be used as a parameter of type "T" in the generic type or method "BaseController <T>". No implicit link

I am trying to create a general one to simplify my codes (this is an api web project), but to some extent it turned out to be more complex than I expected. What I'm trying to implement looks something like this:

My first idea

To simplify all my real code, here is what I wrote:

public interface IDatabaseTable { }

public class ReceiptIndex: IDatabaseTable { }

public interface IBackend<T> where T: IDatabaseTable { }

public class Receipts : IBackend<ReceiptIndex> { }

public class Generic<T> : SyncTwoWayXI, IBackend<T> where T:IDatabaseTable { }

public class BaseController<T> : ApiController where T: IBackend<IDatabaseTable>, new () { }

The entire line created separately in a separate file.

When I try to create a controller that inherits from BaseController

public class ReceiptsBaseController : BaseController<Receipts>

I get an error

The type "Receipts" cannot be used as a parameter of type "T" in the general type or method "BaseController". There is no implied switching of links from "Receipts" to "IBackend".

-, . - , , -, , .

+4
4

T IBackend. :

public class BaseController<T, TBackEndSubType> : ApiController
    where T : IBackend<TBackEndSubType>, new()
    where TBackEndSubType : IDatabaseTable { }

public class ReceiptsBaseController : BaseController<Receipts, ReceiptIndex> { }
+1

, , :

public class BaseController<TBackend, TDatabaseTable>
    : ApiController
    where TBackend : IBackend<TDatabaseTable>, new() 
    where TDatabaseTable: IDatabaseTable
{ }

public class ReceiptsBaseController : BaseController<Receipts, ReceiptIndex>
{
}

, , .

+4

BaseController :

where T: IBackend<IDatabaseTable>

IBackend <ReceiptIndex> , IBackend <IDatabaseTable> . 2 BaseController:

public class BaseController<TBackend, TDatabaseTable> : ApiController 
    where TDatabaseTable: IDatabaseTable 
    where TBackend: IBackend<TDatabaseTable>, new () { }

:

public class ReceiptsBaseController : BaseController<Receipts, ReceiptIndex>
0

out: https://msdn.microsoft.com/en-us/library/dd469487.aspx

IBackend :

 public interface IBackend<out T> where T : IDatabaseTable { }
0

All Articles