Created
May 14, 2014 19:57
-
-
Save hypesystem/3df5a448f4b3c392704d to your computer and use it in GitHub Desktop.
Range<T>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
/// <summary> | |
/// Generic implementation of Martin Fowler's Enterprise Pattern ``Range'': | |
/// http://martinfowler.com/eaaDev/Range.html | |
/// | |
/// TODO: Open-ended ranges (use named parameters, so ``new Range(start: 3)'' is | |
/// ``greater-than-or-equals 3''. | |
/// TODO: Inclusive/exclusive setting for start and end values. ([1,3] v ]1,3[) | |
/// TODO: Empty range | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
public struct Range<T> where T : IComparable<T> | |
{ | |
private readonly T _start, _end; | |
public Range(T start, T end) | |
{ | |
_start = start; | |
_end = end; | |
} | |
public T Start | |
{ | |
get | |
{ | |
return _start; | |
} | |
} | |
public T End | |
{ | |
get | |
{ | |
return _end; | |
} | |
} | |
public bool Includes(T element) | |
{ | |
return element.CompareTo(_start) >= 0 && element.CompareTo(_end) <= 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment