Class Range<T>
- Namespace
- ArcanaDevelopment.adTempus.Shared
- Assembly
- ArcanaDevelopment.adTempus.Shared.dll
Represents a range of values
public class Range<T> where T : struct, IComparable<T>
Type Parameters
| Name | Description |
|---|---|
T |
- Inheritance
-
objectRange<T>
Constructors
Range(T?, T?)
Creates a new Range for the specified start and end values
public Range(T? start, T? end)
Parameters
| Name | Type | Description |
|---|---|---|
start |
T? | The starting (minimum) value for the range. |
end |
T? | The ending (maximum) value for the range. |
Remarks
If Min > Max, the values are swapped.
Range(T?, T?, string)
Creates a new Range for the specified start and end values
public Range(T? start, T? end, string rangeSeparator)
Parameters
| Name | Type | Description |
|---|---|---|
start |
T? | The starting (minimum) value for the range. |
end |
T? | The ending (maximum) value for the range. |
rangeSeparator |
string | The separator to use between range values in string representations |
Range(T)
Creates a new Range for a single value
public Range(T value)
Parameters
| Name | Type | Description |
|---|---|---|
value |
T | The single value for the range |
Remarks
Fields
DefaultNegateIndicator
The default string to denote that the range should be negated.
public const string DefaultNegateIndicator = "!"
Field Value
- string
DefaultRangeSeparator
The default string to use to separate values in a range.
public const string DefaultRangeSeparator = "-"
Field Value
- string
Max
The maximum value (inclusive)
public T? Max
Field Value
- T?
Min
The minimum value (inclusive)
public T? Min
Field Value
- T?
Negate
Indicates whether the range is negated
public bool Negate
Field Value
- bool
Remarks
If Negate is true, the
NegateIndicator
The string to use denote that the range should be negated.
public string NegateIndicator
Field Value
- string
RangeSeparator
The string to use to separate values when converting the range to a string.
public string RangeSeparator
Field Value
- string
Remarks
Defaults to the DefaultRangeSeparator.
Properties
IsSingleValue
public bool IsSingleValue { get; }
Property Value
- bool
Methods
Contains(T)
Indicates whether the specified value meets the rules for the range
public bool Contains(T value)
Parameters
| Name | Type | Description |
|---|---|---|
value |
T | The value to test against the range. |
Returns
- bool
Remarks
If Negate is false, Contains returns true if Min <= value Min <= Max.
If Negate is true, Contains returns true if value < Min and value > Max
ToString()
Returns a string representation of the range.
public override string ToString()
Returns
- string
Remarks
If Min and Max are equal, returns Min. If they are different, returns the two values separated by the RangeSeparator.
TryParse(string, out Range<T>)
Attempts to parse a Range from a string representation
public static bool TryParse(string source, out Range<T> result)
Parameters
| Name | Type | Description |
|---|---|---|
source |
string | The string to parse |
result |
Range<T> | Returns the parsed range |
Returns
- bool
A boolean value indicating whether the
sourcewas successfully parsed.
Remarks
The source must be a valid string representation of a single T value or of two
T values separated by the DefaultRangeSeparator.
TryParse(string, string, out Range<T>)
Attempts to parse a Range from a string representation
public static bool TryParse(string source, string separator, out Range<T> result)
Parameters
| Name | Type | Description |
|---|---|---|
source |
string | The string to parse |
separator |
string | The string that separates values in the range. The RangeSeparator of the returned Range will be set to this value. |
result |
Range<T> | Returns the parsed range |
Returns
- bool
A boolean value indicating whether the
sourcewas successfully parsed.
Remarks
The source must be a valid string representation of a single T value or of two
T values separated by the separator.