Core Library for .NET

Essential abstractions and utilities for clean, consistent .NET code, with explicit, exception-free error handling built in.

What's inside

Discover the capabilities built to elevate your .NET applications.

Results Instead of Exceptions

Result and Result<T> return success or failure as a value, so a method's signature says it can fail and callers can't ignore it. Result.Of wraps code that might throw and captures the exception as a Failure, and Match, Select and SelectMany run the next step only when the last one succeeded.

Every operation has Task and ValueTask overloads, with cancellation, so asynchronous code composes the same way.

Optional Values

Optional<T> makes absence explicit, with distinct Some and None states instead of null. Map, flatten and match optional values fluently, turn them into results, and read them with a default or a clear exception. Asynchronous overloads cover Task and ValueTask throughout, and FirstOrNone, LastOrNone and SingleOrNone bring the same safety to sequences.

Composable Specifications

Specification<T> captures a business rule as an expression tree, so you write it once and reuse it everywhere. Combine rules with And, Or and Not, test an object with IsSatisfiedBy, or filter an IEnumerable or IQueryable with Where and WhereNot. Combined rules stay plain expression trees, so query providers can translate them into database queries.

Smart Enumerations

Enumeration<T> replaces bare enums with strongly typed classes that can carry data and behaviour of their own. Look entries up by name or value, list them all, and compare them by value. Each type's entries are discovered once and cached in frozen collections, so lookups stay fast.

Guard Clauses

Preconditions that read like the rule they enforce. Check methods throw InvalidOperationException and Require methods throw the appropriate ArgumentException, covering null and empty values, ranges, defined enum values, and the state of optionals and results. The argument name is captured automatically, each method returns the value it checked so it can be used inline, and interpolated messages are only built when a check fails.

Value Semantics

IValueEquatable<T> and IValueComparable<T> extend .NET's equality and comparison interfaces to require the matching operators, so a value type's operators can't be forgotten or drift out of step with Equals and CompareTo. Equality comparers for optionals and results compare by content, and accept a custom comparer for the value inside.

Strongly Typed Text Encodings

Base16, Base32, Base58 and Base64 are value types of their own, so encoded text is never mistaken for an ordinary string. They parse and format through .NET's standard interfaces, and format providers cover the common alphabets: uppercase and lowercase hex; RFC 4648, z-base-32, Geohash, Crockford and Base32hex, with or without padding; and the Bitcoin, Flickr and Ripple alphabets for Base58.

Binary Conversion

IBinaryConvertible, IMemoryBinaryConvertible and ISpanBinaryConvertible give types a standard way to expose their underlying bytes as a read-only span or memory. The encoded text types implement them, and so can your own types, for serialisation, hashing and other low-level work.

LINQ Extensions

The queries LINQ leaves out: AllEqualBy and AnyEqualBy, None and CountNot, IsEmpty and IsSingle, WhereNot and WhereNotNull, Sum and SumBy for any numeric type through generic math, content-based hash codes, and JoinToString for turning a sequence into readable text.

Collection Factories

ListOf, HashSetOf, DictionaryOf and their sorted and immutable counterparts build typed collections in a single call, and EmptyList, EmptyDictionary and the rest give you empty ones without spelling out their types.

Everyday Extensions

Helpers for the tasks every codebase repeats: the substring before or after a delimiter, the nth occurrence of a character, Kotlin-style Apply and Let scope functions, record-style string output for any object, range checks for anything comparable, StringBuilder trimming, wrapping and prepending, and conversions between dates, times, strings and bytes.

C# Type Names

GetCSharpTypeDeclaration turns a runtime type into the name you'd write in C#, such as List<int?> or (string, int), rather than the CLR's List`1. Flags control namespaces, keyword aliases, nullable shorthand, generic arguments and tuple syntax, so diagnostics and logs show types the way developers read them.

Built for Modern .NET

Targets .NET 8, 9 and 10, uses C# 14 extension members to add guard clauses and helpers where you'd naturally look for them, and has no third-party dependencies.