Xpandables.Primitives 10.0.2

dotnet add package Xpandables.Primitives --version 10.0.2
                    
NuGet\Install-Package Xpandables.Primitives -Version 10.0.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="Xpandables.Primitives" Version="10.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Xpandables.Primitives" Version="10.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Xpandables.Primitives" />
                    
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 Xpandables.Primitives --version 10.0.2
                    
#r "nuget: Xpandables.Primitives, 10.0.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 Xpandables.Primitives@10.0.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=Xpandables.Primitives&version=10.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Xpandables.Primitives&version=10.0.2
                    
Install as a Cake Tool

System.Primitives

NuGet NuGet Downloads .NET License

Core primitives and foundational utilities for the Xpandables.Net ecosystem.

📖 Overview

System.Primitives (NuGet: Xpandables.Primitives) provides strongly-typed primitive value objects, collections, dispose patterns, state machine abstractions, caching, text generation/cryptography, and shared DI extensions used across all Xpandables packages. Root namespace: System.

Built for .NET 10 and C# 14.

✨ Features

🏷️ Primitive Value Objects

Type File Description
IPrimitive IPrimitive.cs Base interface exposing object Value
IPrimitive<TValue> IPrimitive.cs Strongly-typed value wrapper
IPrimitive<TPrimitive, TValue> IPrimitive.cs Full generic — creation, comparison, formatting, implicit conversions

📦 Collections

Type File Description
ElementCollection Collections/ElementCollection.cs Immutable record struct with O(1) key lookup and JSON support
ElementEntry Collections/ElementEntry.cs Key + StringValues pair
EnumerableExtensions Collections/EnumerableExtensions.cs Extension methods on IEnumerable<T>
HttpHeadersExtensions Collections/HttpHeadersExtensions.cs HTTP header conversion helpers
ValidationResultExtensions Collections/ValidationResultExtensions.cs ValidationResult collection helpers
QueryableEmpty<T> Collections/QueryableEmpty.cs Empty IQueryable<T> implementation

♻️ Dispose Patterns

Type File Description
Disposable Disposable.cs Abstract IDisposable base with IsDisposed guard
DisposableAsync DisposableAsync.cs Abstract IAsyncDisposable base with IsDisposed guard

🔄 State Machine

Type File Description
IState / IState<TStateContext> States/IState.cs State with EnterStateContext / ExitStateContext
IStateContext States/IStateContext.cs Context for state transitions
StateContext States/StateContext.cs Default implementation
IOriginator / IMemento States/ Memento pattern support
State States/State.cs Base state implementation

🔐 Text Utilities

Type File Description
TextGenerator TextGenerator.cs Cryptographically secure random string generation
TextCryptography TextCryptography.cs AES encrypt/decrypt and secure comparison
EncryptedValue TextCryptography.cs Record struct — Key, Value, Salt

💾 Caching

Type File Description
MemoryAwareCache<TKey, TValue> Cache/MemoryAwareCache.cs Thread-safe weak-reference cache with auto-cleanup
ICacheTypeResolver / CacheTypeResolver Cache/ Cache type discovery

🛠️ Utilities

Type File Description
LazyResolved<T> LazyResolved.cs Lazy<T> resolved from IServiceProvider
IHttpStatusCodeExtension IHttpStatusCodeExtension.cs Custom HTTP status code mapping
StringExtensions StringExtensions.cs String helpers
ObjectExtensions ObjectExtensions.cs Object helpers
ExceptionExtensions ExceptionExtensions.cs Exception helpers
JsonSerializerExtensions JsonSerializerExtensions.cs System.Text.Json helpers

🔧 Composition

Type File Description
IAddService Composition/IAddService.cs Interface for modular service registration
ExportOptions Composition/ExportOptions.cs MEF export configuration

⚙️ Dependency Injection

C# 14 extension members on IServiceCollection (namespace: Microsoft.Extensions.DependencyInjection).

services.AddXHttpStatusCodeExtension();       // IHttpStatusCodeExtension (Singleton)
services.AddXHttpStatusCodeExtension<T>();     // Custom implementation
services.AddXCacheTypeResolver();             // ICacheTypeResolver (Singleton)
services.AddXCacheTypeResolver<T>();           // Custom implementation

📦 Installation

dotnet add package Xpandables.Primitives

Dependencies: Microsoft.Extensions.Configuration, Microsoft.Extensions.Configuration.Json, Microsoft.Extensions.Configuration.EnvironmentVariables, Microsoft.Extensions.DependencyInjection, Microsoft.Extensions.Primitives

🚀 Quick Start

ElementCollection

using System.Collections;

var errors = ElementCollection.With("Name", "Name is required")
    .Add("Email", "Invalid email");

var merged = errors.Merge(ElementCollection.With("Age", "Must be 18+"));

Text Cryptography

EncryptedValue encrypted = TextCryptography.Encrypt("my-secret");
string decrypted = TextCryptography.Decrypt(encrypted);
bool match = TextCryptography.Compare(encrypted, "my-secret");

MemoryAwareCache

using System.Cache;

var cache = new MemoryAwareCache<string, MyService>(
    cleanupInterval: TimeSpan.FromMinutes(5),
    maxAge: TimeSpan.FromHours(1));

cache.TryAdd("key", myService);

📄 License

Apache License 2.0 — Copyright © Kamersoft 2025

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on Xpandables.Primitives:

Package Downloads
Xpandables.AsyncPaged

IAsyncPagedEnumerable implementation.

Xpandables.Events

Events implementation.

Xpandables.Results

Result pattern implementation.

Xpandables.Composition

Composition classes.

Xpandables.Rests

Http Rest Implementation.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.2 68 3/15/2026
10.0.1 206 2/20/2026
10.0.0 212 1/9/2026