-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRange.cs
More file actions
43 lines (35 loc) · 1.22 KB
/
Range.cs
File metadata and controls
43 lines (35 loc) · 1.22 KB
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
namespace System
{
public readonly struct Range : IEquatable<Range>
{
public Index Start { get; }
public Index End { get; }
private Range(Index start, Index end)
{
Start = start;
End = end;
}
public override bool Equals(object value)
{
if (value is Range)
{
Range r = (Range)value;
return r.Start.Equals(Start) && r.End.Equals(End);
}
return false;
}
public bool Equals(Range other) => other.Start.Equals(Start) && other.End.Equals(End);
public override int GetHashCode()
{
return Start.GetHashCode() ^ End.GetHashCode();
}
public override string ToString()
{
return Start + ".." + End;
}
public static Range Create(Index start, Index end) => new Range(start, end);
public static Range FromStart(Index start) => new Range(start, new Index(0, fromEnd: true));
public static Range ToEnd(Index end) => new Range(new Index(0, fromEnd: false), end);
public static Range All() => new Range(new Index(0, fromEnd: false), new Index(0, fromEnd: true));
}
}