Bodu Namespace
- Package
-
Bodu.Core 1.3.0
Purpose
The root Bodu namespace holds the cross-cutting primitives that the rest of Bodu.Core - and the wider solution - build on: the calendar value sets, the centralized argument-validation helper, and a small pluggable random-number abstraction. These types are namespace-root on purpose: they are used everywhere and carry no sub-domain of their own.
Static documentation
- Bodu.Core introduction - namespaces, headline types, scenarios.
DayOfWeekSetguide - composing, parsing, and enumerating sets of days of the week, and migrating fromWeekPattern.- Calendar value sets guide - the sets of months, days of the month, hours, minutes, and seconds.
Key types
- DayOfWeekSet - an immutable set of days of the week. Built from
DayOfWeekvalues (new DayOfWeekSet(DayOfWeek.Monday, DayOfWeek.Wednesday),With/Without) or taken from the named presets (Weekdays,Weekend,All,Empty, and the regional working weeks such asSundayToThursday); supports the set operators (DayOfWeekSet.Weekdays | DayOfWeekSet.Weekend), parsing, formatting, and enumeration. It replacesWeekPattern, which Bodu.Core 1.3.0 removed. See theDayOfWeekSetguide. - MonthSet, DayOfMonthSet, HourSet, MinuteSet, SecondSet - the same shape over months 1-12, days of the month 1-31, hours 0-23, minutes 0-59, and seconds 0-59, written as a list of values and ranges (
"1-3,12"), every value ("1,2,3,12", formatL) or binary text ("111000000001", formatB), and for months a mask of initials ("JFM________D", formatJ). See the calendar value sets guide. - ICalendarValueSet<TSelf, TValue> - the interface the six calendar value sets implement:
EmptyandAll, membership,WithandWithout, the bits round trip,ParseExactandTryParseExact, formatting, the set operators, equality and enumeration, so generic code can work with any of them. - WorkingDaysOfWeek - an enum naming the common working weeks used by the date and calendar extensions, one member per week (
MondayToFriday,SundayToThursday, ...), withCustomfor a week supplied some other way. It is not a flags enum: its members are not combined, and a set of days is a DayOfWeekSet. - IRandomGenerator - a minimal abstraction over a random source, so algorithms (shuffles, sampling) can be tested deterministically or swapped between PRNG implementations.
- XorShiftRandom - a fast xorshift PRNG that derives from
System.Random; seedable for reproducible sequences. Drop-in whereRandomis expected, faster where throughput matters and cryptographic strength is not required. - ThrowHelper - the centralized argument-validation surface (
ThrowIfNull,ThrowIfLessThan,ThrowIfGreaterThan, span/array offset checks, enum-defined checks, …). Public APIs across the solution validate their parameters through theseThrowIf…members rather than hand-rolled checks.
Example
using Bodu;
// Compose and test a day-of-week set.
DayOfWeekSet weekdays = new DayOfWeekSet(DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday,
DayOfWeek.Thursday, DayOfWeek.Friday); // same set as DayOfWeekSet.Weekdays
DayOfWeekSet fourDay = weekdays.Without(DayOfWeek.Friday);
bool worksSaturday = weekdays.Contains(DayOfWeek.Saturday); // false
// The other calendar fields have sets of their own.
MonthSet quarterEnds = MonthSet.Parse("3,6,9,12");
bool isQuarterEnd = quarterEnds.Contains(DateTime.Today.Month);
// Deterministic randomness for reproducible tests.
IRandomGenerator rng = new XorShiftRandom(seed: 12345);
int roll = rng.Next(6) + 1; // Next(maxValue) yields [0, maxValue) - here a die roll of 1-6
Notes
XorShiftRandomis not cryptographically secure. UseSystem.Security.Cryptography.RandomNumberGeneratorfor security-sensitive randomness.- Validate through
ThrowHelper. When contributing public APIs, prefer an existingThrowIf…helper over a hand-written check; add a new helper only when the rule is general-purpose. - See also: the
DayOfWeekSetguide, the calendar value sets guide, and the Bodu.Collections.Generic overview.
Namespaces
Classes
- ThrowHelper
Provides centralized guard clause methods for argument validation, offering consistent and concise exception throwing across the library.
- XorShiftRandom
Represents a high-performance, non-cryptographic pseudo-random number generator based on Marsaglia's xorshift128 algorithm.
Structs
- DayOfMonthSet
Represents an immutable set of days of the month, 1 to 31.
- DayOfMonthSet.Enumerator
Enumerates the days a DayOfMonthSet selects, in ascending order, without allocating.
- DayOfWeekSet
Represents an immutable set of days of the week.
- DayOfWeekSet.Enumerator
Enumerates the days a DayOfWeekSet selects, in DayOfWeek order, Sunday first, without allocating.
- HourSet
Represents an immutable set of hours of the day, 0 to 23.
- HourSet.Enumerator
Enumerates the hours an HourSet selects, in ascending order, without allocating.
- MinuteSet
Represents an immutable set of minutes of the hour, 0 to 59.
- MinuteSet.Enumerator
Enumerates the minutes a MinuteSet selects, in ascending order, without allocating.
- MonthSet
Represents an immutable set of months of the year, 1 (January) to 12 (December).
- MonthSet.Enumerator
Enumerates the months a MonthSet selects, in ascending order, without allocating.
- SecondSet
Represents an immutable set of seconds of the minute, 0 to 59.
- SecondSet.Enumerator
Enumerates the seconds a SecondSet selects, in ascending order, without allocating.
Interfaces
- ICalendarValueSet<TSelf, TValue>
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.
- IRandomGenerator
Defines the minimal contract for a pluggable, non-cryptographic random-integer source used by shuffle, sampling, and randomized-collection helpers throughout the library.
Enums
- WorkingDaysOfWeek
Represents a named pattern of working days within a seven-day week.