-
Notifications
You must be signed in to change notification settings - Fork 178
/
Copy pathRange.cs
65 lines (56 loc) · 1.54 KB
/
Range.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.Text;
namespace Bot.Builder.Community.Dialogs.Luis
{
public struct Range<T> : IEquatable<Range<T>>, IComparable<Range<T>>
where T : IEquatable<T>, IComparable<T>
{
public Range(T start, T after)
{
this.Start = start;
this.After = after;
}
public T Start { get; }
public T After { get; }
public override bool Equals(object other)
{
return other is Range<T> && this.Equals((Range<T>)other);
}
public override int GetHashCode()
{
return this.Start.GetHashCode() ^ this.After.GetHashCode();
}
public override string ToString()
{
return $"[{this.Start}, {this.After})";
}
public bool Equals(Range<T> other)
{
return this.Start.Equals(other.Start) && this.After.Equals(other.After);
}
public int CompareTo(Range<T> other)
{
if (this.After.CompareTo(other.Start) < 0)
{
return -1;
}
else if (other.After.CompareTo(this.Start) > 0)
{
return +1;
}
else
{
return 0;
}
}
}
public static partial class Range
{
public static Range<T> From<T>(T start, T after)
where T : IEquatable<T>, IComparable<T>
{
return new Range<T>(start, after);
}
}
}