
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 0.49 KB | hits: 11 | expires: Never
Reflexive type parameter constraints: X<T> where T : X<T> ‒ any simpler alternatives?
interface ICloneable
{
ICloneable Clone();
}
class Sheep : ICloneable
{
ICloneable Clone() { … }
} //^^^^^^^^^^
Sheep dolly = new Sheep().Clone() as Sheep;
//^^^^^^^^
interface ICloneable<TImpl> where TImpl : ICloneable<TImpl>
{
TImpl Clone();
}
class Sheep : ICloneable<Sheep>
{
Sheep Clone() { … }
} //^^^^^
Sheep dolly = new Sheep().Clone();