StrongOf 3.1.2

Requires NuGet 2.12 or higher.

dotnet add package StrongOf --version 3.1.2
                    
NuGet\Install-Package StrongOf -Version 3.1.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StrongOf" Version="3.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="StrongOf" Version="3.1.2" />
                    
Directory.Packages.props
<PackageReference Include="StrongOf" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add StrongOf --version 3.1.2
                    
#r "nuget: StrongOf, 3.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package StrongOf@3.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=StrongOf&version=3.1.2
                    
Install as a Cake Addin
#tool nuget:?package=StrongOf&version=3.1.2
                    
Install as a Cake Tool

StrongOf

StrongOf helps to implement primitives as a strong type that represents a domain object (e.g. UserId, EmailAddress, etc.). It is a simple class that wraps a value and provides a few helper methods, preventing parameter-order bugs at compile time.

NativeAOT

The core package supports NativeAOT and trimming on .NET 9 through .NET 11. Both hand-written IStrongOf<TValue, TSelf>.Create implementations and source-generated factories use static dispatch. The source generator executes at build time and is not a runtime dependency.

using StrongOf.SourceGeneration;

[StrongGuid]
public sealed partial class UserId;

Source-generated classes must be top-level, non-generic and partial. UserId<T> is rejected with STRONG005; the generic marker syntax [Strong<Guid>] remains supported.

Set <PublishAot>true</PublishAot> in the consuming application and publish for a specific RID. The core library sets IsAotCompatible=true; its .NET 10+ builds additionally verify referenced AOT metadata with VerifyReferenceAotCompatibility=true. This opt-in check is separate from the code analyzers.

The native example is published and executed in CI for .NET 9/10/11 on Windows x64 and Linux x64. Framework integration packages do not inherit the core package's compatibility guarantee. For JSON, use the generated-context example.

Available Base Types

Base Class Wraps
StrongString<T> string
StrongGuid<T> Guid
StrongInt32<T> int
StrongInt64<T> long
StrongDecimal<T> decimal
StrongDouble<T> double
StrongChar<T> char
StrongBoolean<T> bool
StrongDateTime<T> DateTime
StrongDateTimeOffset<T> DateTimeOffset
StrongTimeSpan<T> TimeSpan

Quick Start

// Define your types using the CRTP pattern
public sealed class UserId(Guid value) : StrongGuid<UserId>(value), IStrongOf<Guid, UserId> { public static UserId Create(Guid value) => new(value); }
public sealed class Email(string value) : StrongString<Email>(value), IStrongOf<string, Email> { public static Email Create(string value) => new(value); }

// Instantiation
UserId userId = new(Guid.NewGuid());  // preferred - fastest
UserId userId2 = UserId.From(Guid.NewGuid()); // via static Create for generic scenarios

// Accessing the value
Guid rawId = userId.Value;

// Nullable factory
UserId? optional = UserId.From(nullableGuid);

// TryParse
bool parsed = UserId.TryParse("550e8400-...", out UserId? id);

// Strongly-typed comparison and sorting
bool equal = userId == userId2;
ids.Sort(); // works via IComparable<T>

Generic TypeConverters

The StrongOf package ships generic TypeConverter implementations for each base type, usable directly in domain types via the [TypeConverter] attribute:

[TypeConverter(typeof(StrongGuidTypeConverter<UserId>))]
public sealed class UserId(Guid value) : StrongGuid<UserId>(value), IStrongOf<Guid, UserId> { public static UserId Create(Guid value) => new(value); }

Available converters: StrongStringTypeConverter<T>, StrongGuidTypeConverter<T>, StrongInt32TypeConverter<T>, StrongInt64TypeConverter<T>, StrongDecimalTypeConverter<T>, StrongDoubleTypeConverter<T>, StrongCharTypeConverter<T>, StrongBooleanTypeConverter<T>, StrongDateTimeTypeConverter<T>, StrongDateTimeOffsetTypeConverter<T>, StrongTimeSpanTypeConverter<T>.

The converters themselves can be instantiated directly in native applications. Reflection-based discovery through TypeDescriptor has its own trimming requirements; a converter attribute does not make an arbitrary consumer framework NativeAOT-compatible.

DateTimeOffset ISO parsing

FromIso8601 and TryParseIso8601 accept timestamps with seconds, zero to seven fractional digits, and Z or an explicit offset. The original offset is preserved. Output uses the round-trip o format. This changes the previous implicit UTC normalization; call Value.ToUniversalTime() explicitly when needed.

Interfaces

  • IStrongOf - base marker interface
  • IStrongString, IStrongGuid, IStrongInt32, etc. - for generic constraints
  • IValidatable - for types that validate their own format via IsValidFormat()

GitHub

See https://github.com/BenjaminAbt/StrongOf

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on StrongOf:

Package Downloads
StrongOf.Json

StrongOf helps to implement primitives as a strong type that represents a domain object (e.g. UserId, EmailAddress, etc.). It is a simple class that wraps a value and provides a few helper methods to make it easier to work with. In contrast to other approaches, StrongOf is above all simple and performant - and not over-engineered.

StrongOf.AspNetCore

StrongOf helps to implement primitives as a strong type that represents a domain object (e.g. UserId, EmailAddress, etc.). It is a simple class that wraps a value and provides a few helper methods to make it easier to work with. In contrast to other approaches, StrongOf is above all simple and performant - and not over-engineered.

StrongOf.FluentValidation

StrongOf helps to implement primitives as a strong type that represents a domain object (e.g. UserId, EmailAddress, etc.). It is a simple class that wraps a value and provides a few helper methods to make it easier to work with. In contrast to other approaches, StrongOf is above all simple and performant - and not over-engineered.

StrongOf.EntityFrameworkCore

StrongOf helps to implement primitives as a strong type that represents a domain object (e.g. UserId, EmailAddress, etc.). It is a simple class that wraps a value and provides a few helper methods to make it easier to work with. In contrast to other approaches, StrongOf is above all simple and performant - and not over-engineered.

StrongOf.Domains

StrongOf helps to implement primitives as a strong type that represents a domain object (e.g. UserId, EmailAddress, etc.). It is a simple class that wraps a value and provides a few helper methods to make it easier to work with. In contrast to other approaches, StrongOf is above all simple and performant - and not over-engineered.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on StrongOf:

Repository Stars
gitextensions/gitextensions
Git Extensions is a standalone UI tool for managing git repositories. It also integrates with Windows Explorer and Microsoft Visual Studio (2015/2017/2019).
Version Downloads Last Updated
3.1.2 844 10/4/2026
3.0.35 404 9/23/2026
3.0.31 3,511 6/17/2026
3.0.29 723 5/19/2026
2.1.37 1,958 4/21/2026
2.1.31 954 3/30/2026
2.1.26 1,018 3/7/2026
2.1.8 288 2/28/2026
2.0.2 482 2/20/2026
1.2.15 3,885 4/26/2025
1.2.8 522 4/9/2025
1.2.7 2,708 2/18/2025
1.2.7-ga639164e54 379 2/18/2025
1.2.4 9,008 11/28/2024
1.2.4-g0988d2c02d 269 11/28/2024
1.2.2 885 11/15/2024
1.2.2-gbc3f3048e7 259 11/15/2024
1.1.4 618 11/12/2024
1.1.4-g6e854f6d6d 245 11/12/2024
1.1.2 362 11/5/2024
Loading failed