I would like to specify a constraint which is another type with a generic argument.
class KeyFrame<T> { public float Time; public T Value; } // I want any kind of Keyframe to be accepted class Timeline<T> where T : Keyframe<*> { }
But this cannot be done in c# as of yet, (and I really doubt it will ever be). Is there any elegant solution to this rather than having to specify the type of the keyframe argument?:
class Timeline<TKeyframe, TKeyframeValue> where TKeyframe : Keyframe<TKeyframeValue>, { }
Read about this from Eric Lippert’s blog Basically, you have to find a way to refer to the type you want without specifying the secondary type parameter.
In his post, he shows this example as a possible solution:
Hope that helps, Troy