Search code examples
genericswhere-clauseboo

Generics in Boo - Is there an equivalent of the C# where clause


Is there a way in Boo to express some constaints on generic types as we can do using the where clause in C#?

In short, how to write?:

class MyClass<T>
    where T:Icomparable<T>
    {...}

Thank you


Solution

  • Yes. The syntax is the same as declaring base types:

    class MyClass[of T(IComparable of T)]
    

    Or, for other constraints:

    class MyClass[of T1(class, constructor), T2(struct)]
    

    I think that the current development version of Boo doesn't support generic type parameter constraints that refer to themselves or to other generic type parameters; I might be mistaken though.