Bodu.Extensions Namespace
- Packages
-
Bodu.Core 1.0.1
Purpose
Bodu.Extensions is the extension-method surface of Bodu.Core. It carries 15+ static classes covering date / time, numeric, span, array, string, enum, comparable, sequence, and stream operations - the framework-style helpers that keep ceremony out of hot paths in the rest of the Bodu solution and in consumer code.
This is the single highest-leverage namespace in Bodu.Core by surface area. Reach for it when you need a DateTime calendar / week operation that the BCL doesn't ship, when you need a decimal-aware significant-digit rounding helper, when you need string SliceSafe / Wrap / Quote / ToSlug / case-conversion utilities, or when you need bit / byte rotation and reversal across the unsigned integer types.
Static documentation
- Bodu.Core introduction -
Bodu.Extensionssummary table. - Bodu.Core getting started - date-arithmetic minimal samples.
Key types grouped by concern
Date and time
- DateTimeExtensions - first / last / next / previous day-of-week within month / quarter / year, ISO week-of-year, day name, weekday tests, midday, end-of-day, truncation. 50+ methods.
- DateOnlyExtensions -
DateOnly-specific equivalents plusAgecalculation. - DateTimeFormatInfoExtensions - a single helper,
LastDayOfWeek(this DateTimeFormatInfo), giving the day that closes a culture's week (derived from itsFirstDayOfWeek). Lives in the sibling Bodu.Globalization.Extensions namespace. - IQuarterDefinitionProvider, IWeekendDefinitionProvider, IWeekendDefinitionProviderExtensions - pluggable calendar-shape providers for non-Gregorian or fiscal quarters and non-Saturday/Sunday weekend conventions.
- FiscalWeekQuarterProvider - a built-in
IQuarterDefinitionProviderthat derives quarters from a fiscal-week pattern (FiscalWeekPattern) for 4-4-5 / 4-5-4 / 5-4-4 retail-calendar workloads. - WorkingDaysOfWeekExtensions, WorkingDaysOfWeek - working-day bitmask helpers.
Calendar-shape enums
- CalendarQuarterDefinition - the quarter-year start convention:
JanuaryToDecember(calendar year),JulyToJune,AprilToMarch,April6ToApril5,March25ToMarch24,OctoberToSeptember,FebruaryToJanuary, andCustom(supplied through anIQuarterDefinitionProvider). - DateTimeResolution - truncation resolution.
- FiscalWeekPattern - fiscal-week enumeration.
- WeekOrdinal -
First,Second,Third,Fourth,Fifth,Last.
Numeric
- NumericExtensions -
Digits,GetBytes,GreatestCommonDivisor,IsPrime,LeastCommonMultiple,ReverseBits,ReverseBytes,ReverseWords,RotateBitsLeft/Right,RoundToSignificantDigits, unchecked arithmetic helpers.
Span, array, stream, buffer
- SpanExtensions -
AsReadOnly,ToReversed(copying; contrast the in-place BCLMemoryExtensions.Reverse). - ArrayExtensions -
Clear,Copy,Pad,Reverse,Slice,ToMatrix. - StreamExtensions -
ReadAllBytes/ReadAllBytesAsync/WriteAllBytes/WriteAllBytesAsync. - BufferConverter -
CopyTo,Read,SwapEndian,ToArrayover byte buffers and primitive types.
Strings
- StringExtensions -
After,Before,Between,Brace,Bracket,CollapseWhitespace,Contains/EndsWith/StartsWithvariants,EnsureEndsWith/EnsureStartsWith,Indent,IsValidIdentifier,Keep/Removevariants,NormalizeLineEndings,Outdent,Parenthesize,Parse,PrefixLines,Quote,RemoveControlCharacters,RemoveDiacritics,SliceSafe, case conversions (ToCamelCase,ToPascalCase,ToSnakeCase,ToKebabCase, …),Truncate,Unwrap,Wrap, slug generation. - IdentifierCase - case convention enum used by
IsValidIdentifier/ case conversions. - SentenceCaseOptions, TitleCaseOptions, WordCasingOptions, SlugOptions - option flags consumed by the casing helpers.
Comparable
- ComparableExtensions -
AtLeast,AtMost,Clamp,IsBetween,IsGreaterThan,Max,Min, … - ComparableHelper -
Coalesce,Max,Minover nullable comparables.
Enums
- EnumExtensions - flag operations:
SetFlag,ClearFlag,HasAllFlags,HasAnyFlag,ToggleFlag, plus bit-conversion helpers between flag enums and their underlying integer representations.
Example
using Bodu.Extensions;
// Calendar arithmetic - first Monday of July, ISO week, age.
DateTime monday = new DateTime(2026, 7, 1).FirstDateOfWeekInMonth(DayOfWeek.Monday);
DateTime endQ = DateTime.Today.LastDateOfQuarter();
int isoWeek = DateTime.Today.IsoWeekOfYear();
int age = new DateOnly(1990, 5, 4).Age();
// Numeric - bit operations and rounding.
uint rotated = 0xDEADBEEFu.RotateBitsLeft(8);
uint reversed = 0x12345678u.ReverseBytes(); // 0x78563412
decimal scaled = 1234.5678m.RoundToSignificantDigits(3); // 1230
// Strings - slug, case conversion, between.
string slug = "Hello, World!".ToSlug(); // "hello-world"
string snake = "FirstName".ToSnakeCase(); // "first_name"
string url = "https://example.com/a/b?x=1".Between("//", "/"); // "example.com"
Notes
- Pure extensions. Every type here is a static class. There are no instance types and no allocations on the helpers themselves; cost is the work they perform on their arguments.
- Culture-aware where it matters. Date / time / culture-sensitive string helpers accept an
IFormatProviderorCultureInfo. The defaults follow the BCL convention (current culture for parsing, invariant culture for format). - Argument validation. All public extension methods go through the centralised ThrowHelper validation surface for null / range / array-length checks.
- Companion namespaces. Sequence-shaping helpers for
IEnumerable<T>/IList<T>live in Bodu.Collections.Extensions and Bodu.Collections.Generic.Extensions. Globalisation-specific date helpers used by the calendar package live in Bodu.Globalization.Extensions. - See also: the Bodu.Core introduction, the
DateTimeExtensions/StringExtensions/NumericExtensionsfull references.
Namespaces
Classes
- ArrayExtensions
Provides allocation-aware operations over Array instances - clearing, copying, slicing, and reversing - that either match the missing primitives on Array or supply more ergonomic counterparts to the BCL helpers.
- BufferConverter
Provides methods for copying and converting between raw byte arrays and arrays of unmanaged types.
- ComparableExtensions
Provides predicate, clamping, and selection operations over any IComparable<T> value, turning common "is this within the expected window?" and "pick the better candidate" decisions into one-liners that read naturally.
- ComparableHelper
Provides null-tolerant ordering helpers -
Min,Max, andCoalesce- for pairs of operands.MinandMaxrequire IComparable<T> operands (reference types may be null);Coalesceis unconstrained and additionally accepts Nullable<T> value types.
- DateOnlyExtensions
Provides calendar-arithmetic operations over DateOnly - age, period anchors, weekday navigation, week and quarter numbering, and culture-aware formatting helpers - that complement the small surface shipped with DateOnly itself.
- DateTimeExtensions
Provides calendar-arithmetic, period-anchoring, ISO-aware, and tick-level operations over DateTime for code that outgrows the BCL surface - fiscal calendars, ISO 8601 week numbering, weekend rules, and high-throughput tick math.
- EnumExtensions
Provides non-boxing bitwise helpers for flag-style enumerations - membership tests and add, remove, and toggle operations that work uniformly across every enum underlying type.
- Enums
Provides type-level helpers for enumerations: cached value and name lookups, parsing, and resolution of values from their DescriptionAttribute or DisplayAttribute text.
- FiscalWeekQuarterProvider
Provides quarter boundary logic for a week-based retail fiscal calendar using a configurable FiscalWeekPattern (5-4-4, 4-5-4, or 4-4-5 week distribution).
- IWeekendDefinitionProviderExtensions
Provides conversions from IWeekendDefinitionProvider to the canonical WeekPattern value type used by the working-week APIs.
- NaturalStringComparer
Provides a numeric-aware ("natural") string comparer that orders embedded runs of ASCII digits by numeric value rather than character by character, so that
"file2"sorts before"file10".
- NotableDateFiscalExtensions
Provides fiscal-period working-day extension methods over DateOnly, resolving the boundary working days of the fiscal year or quarter that contains a date.
- NotableDateOnlyExtensions
Provides working-day, traversal, and notable-date query extension methods over DateOnly, resolved through an explicit INotableDateService for a requested territory.
- NotableDateTimeExtensions
Provides working-day, traversal, and notable-date query extension methods over DateTime, delegating to the DateOnly surface on the date component.
- NotableDateTimeOffsetExtensions
Provides working-day, traversal, and notable-date query extension methods over DateTimeOffset, delegating to the DateOnly surface on the offset-local date component.
- NumericExtensions
Provides bit-level and byte-level transformations over the integral primitive types - endian conversion, byte and word swaps, bit reversal and rotation, and unchecked arithmetic helpers - for hashing, serialization, and protocol code.
- SlugOptions
Supplies separator, casing, diacritic, and length configuration for ToSlug(string, SlugOptions).
- SpanExtensions
Provides span-shaping helpers - read-only conversion and copy-and-reverse operations - for code that already operates on Span<T> or ReadOnlySpan<T>.
- StreamExtensions
Provides whole-payload read and write helpers for Stream - synchronous and asynchronous operations that consume or emit an entire byte buffer in a single call.
- StringExtensions
Provides ergonomic, allocation-aware extension methods on string that fill gaps in the BCL - positive-form null/empty predicates, fluent fallbacks, whitespace and line-ending normalisation, affix management, substring windowing, case conversion, identifier sanitisation, and generic parsing.
- WordCasingOptions
Supplies acronym, minor-word, and culture configuration for the acronym-aware casing converters on StringExtensions.
- WorkingDaysOfWeekExtensions
Provides bidirectional conversion between the WorkingDaysOfWeek enum sugar and the WeekPattern value type.
Interfaces
- IQuarterDefinitionProvider
Defines a provider interface for custom quarter calculation logic based on DateTime or DateOnly values.
- IWeekendDefinitionProvider
Defines a provider interface for determining whether a given DayOfWeek is considered part of the weekend.
Enums
- CalendarQuarterDefinition
Specifies how quarters (Q1-Q4) are defined within a given calendar-based system.
- DateTimeResolution
Specifies the resolution level for a DateTime value.
- FiscalWeekPattern
Specifies the week distribution pattern applied across the three fiscal periods within each quarter of a week-based retail fiscal calendar.
- IdentifierCase
Identifies which casing convention ToIdentifier(string, IdentifierCase) applies to the words detected in the source string after invalid identifier characters have been stripped.
- SentenceCaseOptions
Tunes the behaviour of ToSentenceCase(string, SentenceCaseOptions) beyond the plain capitalise-first-letter-of-each-sentence default.
- TitleCaseOptions
Tunes the behaviour of ToTitleCase(string, TitleCaseOptions) beyond the plain capitalise-each-word default.
- WeekOrdinal
Specifies the ordinal position of a weekday within a given month. Commonly used in recurrence rules, such as "the second Tuesday of the month".