Table of Contents

ICalendarValueSet<TSelf, TValue> Interface

Definition

Namespace
Bodu
Assembly
Bodu.Core.dll
Package
Bodu.Core 1.3.0
Source
ICalendarValueSet{T,T}.cs

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

TSelf

The type that implements the interface.

TValue

The 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

value TValue

The value to test.

Returns

bool

true when the set selects value; false when it does not, including when value is outside the domain.

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

bits ulong

The number that describes the set.

Returns

TSelf

The set bits describes.

Exceptions

ArgumentOutOfRangeException

Thrown when bits sets 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

s ReadOnlySpan<char>

The characters to convert.

format ReadOnlySpan<char>

The format of s, one of those the type writes.

Returns

TSelf

The set the characters describe.

Exceptions

FormatException

Thrown when format is not a supported format, or s is 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

s string

The text to convert.

format string

The format of s, one of those the type writes.

Returns

TSelf

The set the text describes.

Exceptions

ArgumentNullException

Thrown when s or format is null.

FormatException

Thrown when format is not a supported format, or s is not text in that format.

ToString(string?)

Returns the set as text in the specified format.

string ToString(string? format)

Parameters

format string

The format, or null or empty for the default.

Returns

string

The text.

Exceptions

FormatException

Thrown when format is 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

s ReadOnlySpan<char>

The characters to convert.

format ReadOnlySpan<char>

The format of s, one of those the type writes.

result TSelf

When this method returns true, the set the characters describe; otherwise Empty.

Returns

bool

true when format is a supported format and s is text in it; otherwise false.

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

s string

The text to convert.

format string

The format of s, one of those the type writes.

result TSelf

When this method returns true, the set the text describes; otherwise Empty.

Returns

bool

true when format is a supported format and s is text in it; otherwise false.

With(TValue)

Returns a set that also selects the specified value.

TSelf With(TValue value)

Parameters

value TValue

The value to add.

Returns

TSelf

A set that selects value and every value this set selects.

Exceptions

ArgumentOutOfRangeException

Thrown when value is outside the domain.

Without(TValue)

Returns a set that no longer selects the specified value.

TSelf Without(TValue value)

Parameters

value TValue

The value to remove.

Returns

TSelf

A set that selects every value this set selects except value.

Exceptions

ArgumentOutOfRangeException

Thrown when value is outside the domain.

Applies to

ProductVersions
.NET8, 10