Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Recursive type constraint error

By: mylesmcdonnell on Jan 6th, 2012  |  syntax: C#  |  size: 0.26 KB  |  views: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class Entity<T> { }
  2.  
  3. public class MyEntity : Entity<object> { }
  4.  
  5. public class Service<T> where T : Entity<T> { }
  6.  
  7. public class Test
  8. {
  9.    private Service<MyEntity> _service; //Not possible because MyEntity has to be convertible to Entity<MyEntity>
  10. }