I am doing an extension to the interval set of the famous C # C5 library. The IInterval interface defines the interval with comparable endpoints (inactive members deleted):
public interface IInterval<T> where T : IComparable<T> { T Low { get; } T High { get; } }
This works well overall, since spaced endpoints can be comparable as integers, dates, or even strings.
However, sometimes it is useful to calculate the duration of the interval. The interval [3:5) has a duration of 2, and the interval [1PM, 9PM) has a duration of 8 hours. This is not possible for comparable data, since it gives us only the order of the elements, and not their distance, for example. it is difficult to give the distance between two strings. The endpoint type should mainly be interval scaling values .
Is there an interface like IComparable<T> that allows me to compare endpoints in general, but also do things like subtract two endpoints to get a duration and add duration to a lower endpoint to get a high endpoint, which can be used to inherit the IDurationInterval<T> : IInterval<T> interface, for example?
Or more concise: is there an interface for interval scaling values?
c # intervals icomparable c5
Mikkel R. lund
source share