Trellis.Primitives
3.0.0-alpha.513
See the version list below for details.
dotnet add package Trellis.Primitives --version 3.0.0-alpha.513
NuGet\Install-Package Trellis.Primitives -Version 3.0.0-alpha.513
<PackageReference Include="Trellis.Primitives" Version="3.0.0-alpha.513" />
<PackageVersion Include="Trellis.Primitives" Version="3.0.0-alpha.513" />
<PackageReference Include="Trellis.Primitives" />
paket add Trellis.Primitives --version 3.0.0-alpha.513
#r "nuget: Trellis.Primitives, 3.0.0-alpha.513"
#:package Trellis.Primitives@3.0.0-alpha.513
#addin nuget:?package=Trellis.Primitives&version=3.0.0-alpha.513&prerelease
#tool nuget:?package=Trellis.Primitives&version=3.0.0-alpha.513&prerelease
Trellis.Primitives
Strongly typed value objects for .NET, with built-in primitives like EmailAddress and Money plus composite JSON conversion and tracing registration for primitive value objects.
Installation
dotnet add package Trellis.Primitives
The Required*<TSelf> and ScalarValueObject<TSelf, TUnderlying> base classes live in Trellis.Core. The source generator, generated primitive JSON converter, and primitive trace source are bundled inside the Trellis.Core package (transitively referenced by Trellis.Primitives) — no extra package is required.
Quick Example
using Trellis;
using Trellis.Primitives;
// TryCreate returns Result<T>; pattern-match before using the value.
var emailResult = EmailAddress.TryCreate("ada@example.com");
// Money.Create throws on invalid input; use TryCreate for user input.
var subtotal = Money.Create(12.34m, "USD");
var shipping = Money.Create(2.00m, "USD");
// Arithmetic on Money returns Result<Money> (currency-mismatch / overflow safe).
Result<Money> grandTotal = subtotal.Add(shipping);
// Define a custom value object — the source generator emits TryCreate, equality, JSON converters, etc.
// RequiredString rejects null/empty/whitespace and trims by default; RequiredGuid rejects Guid.Empty.
public sealed partial class CustomerEmail : RequiredString<CustomerEmail>;
public sealed partial class OrderId : RequiredGuid<OrderId>;
Key Features
- Ready-to-use value objects for common concepts such as email, URL, money, and percentages.
Trellis.Corebase classes likeRequiredString<CustomerEmail>andRequiredGuid<OrderId>for custom domain types.- Lenient-by-default generated validation (rejects
nullonly); opt into sentinel rejection with[NotDefault]and string trimming with[Trim]when domain strictness is required. - Validation and parsing rules that stay with the type instead of leaking into handlers and controllers.
GeoCoordinatevalidates finite latitude/longitude and calculates approximate in-memory great-circle distances in meters.WeeklyPeriodandWeeklySchedulemodel recurring local-clock availability in an IANA time zone.
Geographic coordinates
var seattle = GeoCoordinate.Create(47.6062, -122.3321);
var portland = GeoCoordinate.Create(45.5152, -122.6784);
double meters = seattle.DistanceMetersTo(portland);
Use TryCreate(latitude, longitude, fieldName) for untrusted input. It accumulates both
component errors; latitude is -90..90 and longitude is -180..180, inclusive. JSON is
{ "latitude": number, "longitude": number }. Values are not rounded or normalized.
Distance uses a sphere of radius 6,371,008.8 meters, not an ellipsoidal model or SQL spatial query.
Weekly availability
var schedule = WeeklySchedule.Create("America/Los_Angeles",
[
WeeklyPeriod.Create(DayOfWeek.Friday, new TimeOnly(22, 0), new TimeOnly(2, 0)),
WeeklyPeriod.CreateAllDay(DayOfWeek.Sunday)
]);
bool available = schedule.IsActiveAt(new DateTimeOffset(2026, 9, 26, 8, 0, 0, TimeSpan.Zero));
Use TryCreate / TryCreateAllDay for untrusted input. Intervals include their start and
exclude their end; an earlier end means the next day. Equal endpoints require the explicit
all-day factory. Empty schedules are always closed. Overlaps are rejected, touching periods
are retained, and input order is normalized without losing TimeOnly tick precision.
The host must supply the IANA time-zone data. Repeated DST clock times both match; skipped
clock times never occur. Use Contains(day, time) for a local-clock query without conversion.
JSON and persistence use application-owned DTOs and validated rehydration, not direct
composite JSON conversion or EF owned-type materialization. Holidays and job scheduling are
outside this primitive's scope.
Documentation
Part of Trellis
This package is part of the Trellis framework.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- OpenTelemetry.Api (>= 1.18.0)
- Trellis.Core (>= 3.0.0-alpha.513)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Trellis.Primitives:
| Package | Downloads |
|---|---|
|
Trellis.EntityFrameworkCore
EF Core integration for Trellis. Convention-based value converter registration for Trellis primitives, Result-returning SaveChanges wrappers, Maybe/Result query extensions, and provider-agnostic database exception classification. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0-alpha.526 | 21 | 9/30/2026 |
| 3.0.0-alpha.524 | 59 | 9/27/2026 |
| 3.0.0-alpha.520 | 83 | 9/25/2026 |
| 3.0.0-alpha.516 | 178 | 9/22/2026 |
| 3.0.0-alpha.513 | 78 | 9/22/2026 |
| 3.0.0-alpha.505 | 200 | 9/13/2026 |
| 3.0.0-alpha.495 | 252 | 8/24/2026 |
| 3.0.0-alpha.458 | 225 | 8/19/2026 |
| 3.0.0-alpha.455 | 147 | 8/19/2026 |
| 3.0.0-alpha.449 | 95 | 8/18/2026 |
| 3.0.0-alpha.447 | 100 | 8/18/2026 |
| 3.0.0-alpha.432 | 166 | 7/6/2026 |
| 3.0.0-alpha.428 | 143 | 7/3/2026 |
| 3.0.0-alpha.425 | 185 | 6/27/2026 |
| 3.0.0-alpha.419 | 111 | 6/24/2026 |
| 3.0.0-alpha.418 | 268 | 6/23/2026 |
| 3.0.0-alpha.417 | 103 | 6/23/2026 |
| 3.0.0-alpha.397 | 148 | 6/18/2026 |
| 3.0.0-alpha.396 | 94 | 6/18/2026 |
| 3.0.0-alpha.394 | 125 | 6/18/2026 |