Xpandables.Primitives
10.0.2
dotnet add package Xpandables.Primitives --version 10.0.2
NuGet\Install-Package Xpandables.Primitives -Version 10.0.2
<PackageReference Include="Xpandables.Primitives" Version="10.0.2" />
<PackageVersion Include="Xpandables.Primitives" Version="10.0.2" />
<PackageReference Include="Xpandables.Primitives" />
paket add Xpandables.Primitives --version 10.0.2
#r "nuget: Xpandables.Primitives, 10.0.2"
#:package Xpandables.Primitives@10.0.2
#addin nuget:?package=Xpandables.Primitives&version=10.0.2
#tool nuget:?package=Xpandables.Primitives&version=10.0.2
System.Primitives
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 | 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
- Microsoft.Extensions.Configuration (>= 10.0.5)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.5)
- Microsoft.Extensions.Configuration.Json (>= 10.0.5)
- Microsoft.Extensions.DependencyInjection (>= 10.0.5)
- Microsoft.Extensions.Primitives (>= 10.0.5)
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.