C# - How to specify generic type constraints for multiple level of inheritance hierarchy? -
i have following class hierarchy
public class entitybase<t> t : entitybase<t> {     //nothing interesting here }  public class benefit : entitybase<benefit> {     //again, nothing interesting here }  public class seasonticketloan : benefit {     //nothing interesting here }   now have got following interface
public interface iquery<t> t : entitybase<t> { }   when try build following class compilation error
public class employeesquery : iquery<seasonticketloan> { }   i error saying seasonticketloan class not satisfy constraint.
the benefit class should have generic type - parent classes have "ultimate"/sealed type generic type. "ultimate"/sealed types have no generic arguments.  
the result in parent classes way through root parent class generic argument contains type of "ultimate"/sealed class , no errors arise.
public class entitybase<t> t : entitybase<t> {     //nothing interesting here }  public class benefit<t> : entitybase<t> t : benefit<t> {     //again, nothing interesting here }  public sealed class seasonticketloan : benefit<seasonticketloan> {     //nothing interesting here }      
Comments
Post a Comment