Your static Create
methods needs to have all of the constraints on it that the Range<T>
class applies to its generic argument:
static class Range
{
public static Range<T> Create<T>(T s, T e, Func<T, T> inc)
where T : IComparable //this line was added
{
return new Range<T>(s, e, inc);
}
}
That's all.
Since the Range
class requires T
to be comparable the Create
method needs to ensure that its own T
is also comparable.
On a side note, you may consider using IComparable<T>
as the constraint for both, rather than IComparable
, to ensure static typing of the comparison.
Convention would also state that Range
implement IEnumerable<T>
rather than IEnumerator<T>
so that the same range can be iterated by multiple sources simultaneously, and it also allows you to use the type in a foreach
loop and with the many other library methods (i.e. all of LINQ) that are built on the IEnumerable<T>
interface.