Class RangeHelper
- Namespace
- Ecng.ComponentModel
- Assembly
- Ecng.ComponentModel.dll
Provides helper methods for manipulating Range objects.
public static class RangeHelper
- Inheritance
-
RangeHelper
- Inherited Members
Methods
Exclude(Range<DateTimeOffset>, Range<DateTimeOffset>)
Excludes the specified DateTimeOffset range from the current range.
public static IEnumerable<Range<DateTimeOffset>> Exclude(this Range<DateTimeOffset> from, Range<DateTimeOffset> excludingRange)
Parameters
from
Range<DateTimeOffset>The original DateTimeOffset range.
excludingRange
Range<DateTimeOffset>The DateTimeOffset range to exclude.
Returns
- IEnumerable<Range<DateTimeOffset>>
A collection of remaining DateTimeOffset ranges after exclusion.
Exclude(Range<DateTime>, Range<DateTime>)
Excludes the specified DateTime range from the current range.
public static IEnumerable<Range<DateTime>> Exclude(this Range<DateTime> from, Range<DateTime> excludingRange)
Parameters
from
Range<DateTime>The original DateTime range.
excludingRange
Range<DateTime>The DateTime range to exclude.
Returns
- IEnumerable<Range<DateTime>>
A collection of remaining DateTime ranges after exclusion.
Exclude(Range<long>, Range<long>)
Excludes the specified long range from the current long range.
public static IEnumerable<Range<long>> Exclude(this Range<long> from, Range<long> excludingRange)
Parameters
Returns
- IEnumerable<Range<long>>
A collection of remaining long ranges after exclusion.
GetRanges(IEnumerable<DateTimeOffset>, DateTimeOffset, DateTimeOffset)
Generates ranges from a sequence of DateTimeOffset values within the specified boundaries.
public static IEnumerable<Range<DateTimeOffset>> GetRanges(this IEnumerable<DateTimeOffset> dates, DateTimeOffset from, DateTimeOffset to)
Parameters
dates
IEnumerable<DateTimeOffset>The sequence of DateTimeOffset values.
from
DateTimeOffsetThe start boundary.
to
DateTimeOffsetThe end boundary.
Returns
- IEnumerable<Range<DateTimeOffset>>
A collection of DateTimeOffset ranges.
GetRanges(IEnumerable<DateTime>, DateTime, DateTime)
Generates ranges from a sequence of DateTime values within the specified boundaries.
public static IEnumerable<Range<DateTime>> GetRanges(this IEnumerable<DateTime> dates, DateTime from, DateTime to)
Parameters
dates
IEnumerable<DateTime>The sequence of DateTime values.
from
DateTimeThe start boundary.
to
DateTimeThe end boundary.
Returns
- IEnumerable<Range<DateTime>>
A collection of DateTime ranges.
GetRanges(IEnumerable<long>, long, long)
Generates ranges based on a sequence of long values (ticks) given the specified start and end boundaries.
public static IEnumerable<Range<long>> GetRanges(this IEnumerable<long> dates, long from, long to)
Parameters
dates
IEnumerable<long>The sequence of long values representing tick counts.
from
longThe starting tick value.
to
longThe ending tick value.
Returns
- IEnumerable<Range<long>>
A collection of ranges represented by long values.
IsEmpty<T>(Range<T>)
Determines whether the specified range is empty, meaning it has no defined minimum or maximum value.
public static bool IsEmpty<T>(this Range<T> range) where T : IComparable<T>
Parameters
range
Range<T>The range to check.
Returns
- bool
true if the range has no minimum and maximum value; otherwise, false.
Type Parameters
T
The type of the range values. Must implement IComparable<T>.
Exceptions
- ArgumentNullException
Thrown when the range is null.
JoinRanges<T>(IEnumerable<Range<T>>)
Joins overlapping or contiguous ranges in the collection.
public static IEnumerable<Range<T>> JoinRanges<T>(this IEnumerable<Range<T>> ranges) where T : IComparable<T>
Parameters
ranges
IEnumerable<Range<T>>The collection of ranges to join.
Returns
- IEnumerable<Range<T>>
A collection of combined ranges.
Type Parameters
T
The type of the range values. Must implement IComparable<T>.
ToRange<T>(SettingsStorage)
Constructs a Range<T> object from the provided SettingsStorage.
public static Range<T> ToRange<T>(this SettingsStorage storage) where T : IComparable<T>
Parameters
storage
SettingsStorageThe SettingsStorage containing the range data.
Returns
- Range<T>
A new Range<T> initialized with the storage values.
Type Parameters
T
The type of the range values. Must implement IComparable<T>.
Exceptions
- ArgumentNullException
Thrown when the storage is null.
ToStorage<T>(Range<T>)
Converts the range to a SettingsStorage object for serialization.
public static SettingsStorage ToStorage<T>(this Range<T> range) where T : IComparable<T>
Parameters
range
Range<T>The range to convert.
Returns
- SettingsStorage
A SettingsStorage object containing the range data.
Type Parameters
T
The type of the range values. Must implement IComparable<T>.
Exceptions
- ArgumentNullException
Thrown when the range is null.