IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
Range.cs
Go to the documentation of this file.
1using System;
5
7{
8 namespace Detail
9 {
21
25 public class RangeT<T> where T : struct, IComparable<T>
26 {
38 public RangeT(T minimum, T maximum, T increment)
39 {
40 if (minimum.CompareTo(maximum) > 0)
41 {
43 "Maximum value has to be bigger than or equal to the minimum value");
44 }
45
46 if (Convert.ToDecimal(increment).CompareTo(Convert.ToDecimal(maximum) - Convert.ToDecimal(minimum)) > 0)
47 {
49 "The given increment is larger than the total range!");
50 }
51
52 Minimum = minimum;
53 Maximum = maximum;
54 Increment = increment;
55 }
56
60 public T Minimum { get; }
61
65 public T Maximum { get; }
66
70 public T Increment { get; }
71
79 public override bool Equals(object? obj)
80 {
81 if (obj is null)
82 {
83 return false;
84 }
85
86 if (ReferenceEquals(this, obj))
87 {
88 return true;
89 }
90
91 if (!(obj is RangeT<T> other))
92 {
93 return false;
94 }
95
96 return Equals(other);
97 }
98
106 protected bool Equals(RangeT<T> other)
107 {
108 return Minimum.Equals(other.Minimum) && Maximum.Equals(other.Maximum) &&
109 Increment.Equals(other.Increment);
110 }
111
115 public override int GetHashCode()
116 {
117 return (Minimum, Maximum, Increment).GetHashCode();
118 }
119
123 public override string ToString()
124 {
125 return Formatting.Invariant(
126 $"{GetType().Name}{{ Minimum = {Minimum}, Maximum = {Maximum}, Increment = {Increment} }}");
127 }
128 }
129 }
130
134
138 public class Range : RangeT<int>
139 {
147 public Range(int minimum, int maximum, int increment)
148 : base(minimum, maximum, increment)
149 {
150 }
151 }
152
156
160 public class RangeU : RangeT<uint>
161 {
169 public RangeU(uint minimum, uint maximum, uint increment)
170 : base(minimum, maximum, increment)
171 {
172 }
173 }
174
178
182 public class RangeU8 : RangeT<byte>
183 {
191 public RangeU8(byte minimum, byte maximum, byte increment)
192 : base(minimum, maximum, increment)
193 {
194 }
195 }
196
200
204 public class RangeF : RangeT<float>
205 {
213 public RangeF(float minimum, float maximum, float increment)
214 : base(minimum, maximum, increment)
215 {
216 }
217 }
218
222
226 public class RangeD : RangeT<double>
227 {
235 public RangeD(double minimum, double maximum, double increment)
236 : base(minimum, maximum, increment)
237 {
238 }
239 }
240}
Exception thrown when an invalid parameter is detected.
Represents a numeric range with defined boundaries and a fixed increment. A Range models a continuous...
Definition Range.cs:26
T Increment
Gets the increment value associated with this range.
Definition Range.cs:70
override int GetHashCode()
Returns a hash code for the current range.
Definition Range.cs:115
RangeT(T minimum, T maximum, T increment)
Initializes a new instance of the RangeT<T> class with specified minimum, maximum,...
Definition Range.cs:38
override bool Equals(object? obj)
Determines whether the specified object is equal to the current range.
Definition Range.cs:79
override string ToString()
Returns a string representation of the range.
Definition Range.cs:123
T Maximum
Gets the upper boundary of the range.
Definition Range.cs:65
T Minimum
Gets the lower boundary of the range.
Definition Range.cs:60
Represents a range with double-precision floating-point boundaries.
Definition Range.cs:227
RangeD(double minimum, double maximum, double increment)
Initializes a new instance of the RangeD class with specified minimum, maximum, and increment values.
Definition Range.cs:235
Represents a range with floating-point boundaries.
Definition Range.cs:205
RangeF(float minimum, float maximum, float increment)
Initializes a new instance of the RangeF class with specified minimum, maximum, and increment values.
Definition Range.cs:213
Represents a range with signed integer boundaries.
Definition Range.cs:139
Range(int minimum, int maximum, int increment)
Initializes a new instance of the Range class with specified minimum, maximum, and increment values.
Definition Range.cs:147
Represents a range with unsigned 8-bit integer boundaries.
Definition Range.cs:183
RangeU8(byte minimum, byte maximum, byte increment)
Initializes a new instance of the RangeU8 class with specified minimum, maximum, and increment values...
Definition Range.cs:191
Represents a range with unsigned integer boundaries.
Definition Range.cs:161
RangeU(uint minimum, uint maximum, uint increment)
Initializes a new instance of the RangeU class with specified minimum, maximum, and increment values.
Definition Range.cs:169