Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.49 KB  |  hits: 11  |  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. Reflexive type parameter constraints:  X<T> where T : X<T> ‒ any simpler alternatives?
  2. interface ICloneable
  3. {
  4.     ICloneable Clone();
  5. }
  6.  
  7. class Sheep : ICloneable
  8. {
  9.     ICloneable Clone() { … }
  10. } //^^^^^^^^^^
  11.  
  12. Sheep dolly = new Sheep().Clone() as Sheep;
  13.                                 //^^^^^^^^
  14.        
  15. interface ICloneable<TImpl> where TImpl : ICloneable<TImpl>
  16. {
  17.     TImpl Clone();
  18. }
  19.  
  20. class Sheep : ICloneable<Sheep>
  21. {
  22.     Sheep Clone() { … }
  23. } //^^^^^
  24.  
  25. Sheep dolly = new Sheep().Clone();