ICalendarValueSet<TSelf, TValue> Interface
Definition
Defines an immutable set of values drawn from a fixed calendar domain of at most 64 values, such as the days of the week or the minutes of an hour.
public interface ICalendarValueSet<TSelf, TValue> : IEquatable<TSelf>, IEqualityOperators<TSelf, TSelf, bool>, IBitwiseOperators<TSelf, TSelf, TSelf>, ISpanParsable<TSelf>, IParsable<TSelf>, IUtf8SpanParsable<TSelf>, ISpanFormattable, IFormattable, IUtf8SpanFormattable, IEnumerable<TValue>, IEnumerable where TSelf : ICalendarValueSet<TSelf, TValue>
Type Parameters
TSelfThe type that implements the interface.
TValueThe type of the values in the domain.
- Inherited Members
- Extension Methods
Examples
static string Describe<TSet, TValue>(TSet set)
where TSet : ICalendarValueSet<TSet, TValue> =>
set == TSet.All ? "all" : $"{set.Count} selected: {set}";
Describe<MonthSet, int>(new MonthSet(1, 4, 7, 10)); // "4 selected: 1,4,7,10"
Describe<DayOfWeekSet, DayOfWeek>(DayOfWeekSet.Weekdays); // "5 selected: _MTWTF_"
Remarks
DayOfWeekSet, MonthSet, DayOfMonthSet, HourSet, MinuteSet and SecondSet implement it, so generic code can test, combine, write and read any of them. A set is a value: members that change it, such as With(TValue) and the operators, return a new set, and two sets are equal when they select the same values.
The operators are the set operations within the domain: | is the union, & the intersection,
^ the symmetric difference, and ~ the complement, every value of the domain the set does not select.
Each value of the domain has a position, from 0 for the first value to one less than the domain's size for the last.
ToUInt64() describes a set as the number whose bit n is set when the set selects the value at
position n, and FromUInt64(ulong) creates the set such a number describes, so equal sets give
equal numbers.
Each type documents its domain, its text forms and the formats ToString(string?) and ParseExact(string, string) accept. Every text form is ASCII, so the members that write to or read from a span of characters or of UTF-8 bytes handle the same text as the members that take and return a string.
Properties
All
Gets the set that selects every value of the domain.
public static abstract TSelf All { get; }
Property Value
- TSelf
Count
Gets the number of values the set selects.
int Count { get; }
Property Value
- int
A number from 0 to the size of the domain.
Empty
Gets the set that selects no value.
public static abstract TSelf Empty { get; }
Property Value
- TSelf
Methods
Contains(TValue)
Determines whether the set selects the specified value.
bool Contains(TValue value)
Parameters
valueTValueThe value to test.
Returns
FromUInt64(ulong)
Creates the set that a number describes, bit n selecting the value at position n of the domain.
public static abstract TSelf FromUInt64(ulong bits)
Parameters
bitsulongThe number that describes the set.
Returns
- TSelf
The set
bitsdescribes.
Exceptions
- ArgumentOutOfRangeException
Thrown when
bitssets a bit at a position past the end of the domain, which selects no value.
ParseExact(ReadOnlySpan<char>, ReadOnlySpan<char>)
Converts a span of characters in the specified format into a set.
public static abstract TSelf ParseExact(ReadOnlySpan<char> s, ReadOnlySpan<char> format)
Parameters
sReadOnlySpan<char>The characters to convert.
formatReadOnlySpan<char>The format of
s, one of those the type writes.
Returns
- TSelf
The set the characters describe.
Exceptions
- FormatException
Thrown when
formatis not a supported format, orsis not text in that format.
ParseExact(string, string)
Converts text in the specified format into a set.
public static abstract TSelf ParseExact(string s, string format)
Parameters
Returns
- TSelf
The set the text describes.
Exceptions
- ArgumentNullException
Thrown when
sorformatis null.- FormatException
Thrown when
formatis not a supported format, orsis not text in that format.
ToString(string?)
Returns the set as text in the specified format.
string ToString(string? format)
Parameters
Returns
- string
The text.
Exceptions
- FormatException
Thrown when
formatis not a supported format.
ToUInt64()
Returns the number that describes the set, bit n set when the set selects the value at position n
of the domain.
ulong ToUInt64()
Returns
- ulong
The number, with no bit set at a position past the end of the domain.
TryParseExact(ReadOnlySpan<char>, ReadOnlySpan<char>, out TSelf)
Attempts to convert a span of characters in the specified format into a set.
public static abstract bool TryParseExact(ReadOnlySpan<char> s, ReadOnlySpan<char> format, out TSelf result)
Parameters
sReadOnlySpan<char>The characters to convert.
formatReadOnlySpan<char>The format of
s, one of those the type writes.resultTSelfWhen this method returns true, the set the characters describe; otherwise Empty.
Returns
TryParseExact(string?, string?, out TSelf)
Attempts to convert text in the specified format into a set.
public static abstract bool TryParseExact(string? s, string? format, out TSelf result)
Parameters
sstringThe text to convert.
formatstringThe format of
s, one of those the type writes.resultTSelfWhen this method returns true, the set the text describes; otherwise Empty.
Returns
With(TValue)
Returns a set that also selects the specified value.
TSelf With(TValue value)
Parameters
valueTValueThe value to add.
Returns
- TSelf
A set that selects
valueand every value this set selects.
Exceptions
- ArgumentOutOfRangeException
Thrown when
valueis outside the domain.
Without(TValue)
Returns a set that no longer selects the specified value.
TSelf Without(TValue value)
Parameters
valueTValueThe value to remove.
Returns
- TSelf
A set that selects every value this set selects except
value.
Exceptions
- ArgumentOutOfRangeException
Thrown when
valueis outside the domain.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |