Barotrauma Client Doc
Range.cs
1 #nullable enable
2 using System;
3 
4 namespace Barotrauma
5 {
9  public struct Range<T> where T : notnull, IComparable<T>
10  {
11  private T start; private T end;
12  public T Start
13  {
14  get { return start; }
15  set
16  {
17  start = value;
18  VerifyStartLessThanEnd();
19  }
20  }
21 
22  public T End
23  {
24  get { return end; }
25  set
26  {
27  end = value;
28  VerifyEndGreaterThanStart();
29  }
30  }
31 
32  public readonly bool Contains(in T v)
33  => start.CompareTo(v) <= 0 && end.CompareTo(v) >= 0;
34 
35  private void VerifyStartLessThanEnd()
36  {
37  if (start.CompareTo(end) > 0) { throw new InvalidOperationException($"Range<{typeof(T).Name}>.Start set to a value greater than End ({start} > {end})"); }
38  }
39 
40  private void VerifyEndGreaterThanStart()
41  {
42  if (end.CompareTo(start) < 0) { throw new InvalidOperationException($"Range<{typeof(T).Name}>.End set to a value less than Start ({end} < {start})"); }
43  }
44 
45  public Range(T start, T end)
46  {
47  this.start = start; this.end = end;
48  VerifyEndGreaterThanStart();
49  }
50  }
51 }
An inclusive range, i.e. [Start, End] where Start <= End
Definition: Range.cs:10
readonly bool Contains(in T v)
Range(T start, T end)
Definition: Range.cs:45