Table of Contents

Class RangeList<T>

Namespace
ArcanaDevelopment.adTempus.Shared
Assembly
ArcanaDevelopment.adTempus.Shared.dll

A collection of Range<T> values.

public class RangeList<T> : List<Range<T>> where T : struct, IComparable<T>

Type Parameters

NameDescription
T
Inheritance
object
List<Range<T>>
RangeList<T>

Remarks

This specialized List contains methods for reading from and writing to a string representation. It handles range notation such as:

1,2-8,12,15-17,23

.

Constructors

RangeList()

Creates a new list

public RangeList()

RangeList(IEnumerable<Range<T>>)

Creates a new list and copies the elements from the source

public RangeList(IEnumerable<Range<T>> source)

Parameters

NameTypeDescription
source IEnumerable<Range<T>>

RangeList(string)

Creates a new list and adds items parsed from the source

public RangeList(string source)

Parameters

NameTypeDescription
source string

The string to parse and add values from.

Remarks

This method calls Add(string, bool) to parse the source. Invalid values are ignored. To validate the source, call Add(string, bool) directly.

RangeList(string, string)

Creates a new list and adds items parsed from the source

public RangeList(string source, string valueSeparator)

Parameters

NameTypeDescription
source string

The string to parse and add values from.

valueSeparator string

The string that separates ranges in the list.

Remarks

This method calls Add(string, bool) to parse the source.

Fields

DefaultValueSeparator

The default string used to separate values in the list.

public const string DefaultValueSeparator = ","

Field Value

string

ValueSeparator

The string that separates values in the list.

public string ValueSeparator

Field Value

string

Methods

Add(string, bool)

Adds range values parsed from a string.

public bool Add(string source, bool ignoreInvalidItems = true)

Parameters

NameTypeDescription
source string

The string to parse.

ignoreInvalidItems bool

If true, any items in the string that cannot be parsed are ignored. If false, any invalid items cause the method to return false without adding any items.

Returns

bool

trueIf ignoreInvalidItems is true, always returns true. Otherwise, returns true if all items in the list were valid and added to the list. If the return value is false, the source contained one or more invalid values, and no items were added to the list.

Remarks

The source must contain zero or more range values, separated by ValueSeparator.

Contains(T)

Indicates whether the value meets the rules for any range in the collection.

public bool Contains(T value)

Parameters

NameTypeDescription
value T

The value to compare to the ranges

Returns

bool

Remarks

This operation returns true as soon as value satisfies the rules for a range in the collection. A range with Negate set to true that conflicts with a non-Negated range does not exclude values that match both. For example if the collection contains a range for 1-5 and another range for !3-8, Contains will return true for a value 4 (and for any other number <=5 or >8).

IsValidList(string)

Indicates whether a string contains a valid list of ranges

public static bool IsValidList(string value)

Parameters

NameTypeDescription
value string

The string to check

Returns

bool

Returns true if the value contains at least one valid range and contains no invalid items. Returns false if value is empty or contains any invalid items.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

Extension Methods