c# - The type cannot be used as type parameter 'T' in the generic type or method 'BaseController<T>'. There is no implicit reference -
i'm trying create generic simplify codes (it's web api project), @ somehow it's ended becoming more complicated expected. i'm trying implement this:
to simplify whole real code, i've written:
public interface idatabasetable { } public class receiptindex: idatabasetable { } public interface ibackend<t> t: idatabasetable { } public class receipts : ibackend<receiptindex> { } public class generic<t> : synctwowayxi, ibackend<t> t:idatabasetable { } public class basecontroller<t> : apicontroller t: ibackend<idatabasetable>, new () { }
all of line above created separately in own file.
when try create controller inherit basecontroller
public class receiptsbasecontroller : basecontroller<receipts>
i error said
the type 'receipts' cannot used type parameter 't' in generic type or method 'basecontroller'. there no implicit reference conversion 'receipts' 'ibackend'.
i try find similar problem , end called covariance , contravariance problem. can give feedback i'm trying or maybe can simplify it.
you can try specify t
in ibackend. this:
public class basecontroller<t, tbackendsubtype> : apicontroller t : ibackend<tbackendsubtype>, new() tbackendsubtype : idatabasetable { } public class receiptsbasecontroller : basecontroller<receipts, receiptindex> { }
Comments
Post a Comment