Lyo.Common 1.0.0

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

Lyo.Common

Cross-cutting primitives shared across the Lyo library suite: ID generators, file/MIME/language/HTTP/file-size metadata, geometry, secure RNG, typed extension classes, and shared System.Text.Json options.

Note — earlier versions of this README also described Ensure, Error, ErrorBuilder, and Result* types. Those live in Lyo.Result, not here. Lyo.Common has no dependency on results — it sits below them and provides primitives that the rest of the > framework composes.

Features

  • ID generators (Identifiers/) — Ksuid, LyoGuid, NanoId, Snowflake, Ulid, and AutoIncrementIdGenerator for thread-safe, sortable identifiers.
  • Record metadata catalogs (Records/) — FileTypeInfo (.GetFileTypeFromExtension, MIME mapping, two-key envelope suffix, common storage-resolution suffix list), FileSizeUnitInfo, HttpStatusCodeInfo, PortInfo (well-known ports + PortCategory, FromPort/FromName/ByCategory, implicit int), LanguageCodeInfo, ProgrammingLanguageInfo, BoundingBox2D.
  • Enum catalogs (Enums/) — FileTypeFlags, MimeType, PortCategory, language and HTTP enums with metadata-attribute lookups.
  • Typed extension classes (Extensions/) — StringExtensions (truncate, ellipsis, case helpers), ScalarExtensions (ToScalar<T>, parsing helpers), DictionaryExtensions ( GetValueAs<T>), StreamExtensions (bounded reads, copy helpers), EnumMetadataExtensions, LanguageExtensions, TypeInfoExtensions.
  • CollectionExtensions — materialization helpers (AsListOrToList, AsReadOnlyCollectionOrToList) that avoid redundant copies when the source is already the right shape.
  • Utilities — small shared helpers (SafeDispose, file-size conversions, expression-based property-path extraction).
  • Pathing (Pathing/) — PathStyle (Host / Posix) and PathHelpers for combine, full-path normalize (./..), file/dir name, SanitizeFileName, and under-root jail checks with Uri-style throw helpers (ThrowIfEscapesRoot, ThrowIfInvalidPath).
  • Cryptographic random (Security/CryptographicRandom) — RandomNumberGenerator-backed byte / int / string helpers, used by other Lyo packages instead of System.Random for anything security-adjacent.
  • Disposable — convenience base / lambda disposable.
  • HashCodeHelpersHashCode.Combine-style helpers for netstandard2.0.
  • LyoJsonSerializerOptions — shared JsonSerializerOptions (case-insensitive, ignore-null, enum-as-string) plus converters in JsonConverters/ that other packages reuse.

Examples

Quick Start

using Lyo.Common.Identifiers;
using Lyo.Common.Records;
using Lyo.Common.Extensions;
using Lyo.Common.Enums;

// IDs
string ksuid = Ksuid.NewId(); // sortable 27-char base62
string nano = NanoId.New(size: 21); // url-safe random
string ulid = Ulid.NewUlid();
Guid guid = LyoGuid.NewSequential();

// File metadata
FileTypeInfo? type = "report.pdf".GetFileTypeFromExtension();
MimeType? mime = "photo.jpg".GetMimeTypeFromExtension();
string? mimeString = mime?.ToMimeString();

// Strings / scalars
string truncated = id.Truncated(start: 6, end: 28);
int parsed = "42".ToScalar<int>();

// JSON
var options = LyoJsonSerializerOptions.Default;

Conversion

using Lyo.Common.Conversion;

// Throwing conversions (TypeConversionException on failure)
int i = TypeConversion.ConvertTo<int>("42");
Guid id = TypeConversion.ConvertTo<Guid>("0d64a685-2fa2-4c48-b06c-b9b0ac9f6a2e");
object? any = TypeConversion.ConvertTo(value, targetType);
int[] ints = (int[])TypeConversion.ConvertToWithCollections(jsonArray, typeof(int[]))!;

// Non-throwing variants
if (TypeConversion.TryConvertTo<DateTime>(value, out var when)) { /* ... */ }
int port = TypeConversion.ConvertToOrDefault("8080", defaultValue: 80);

// Strings that look like JSON ({ or [) deserialize into complex targets as a last resort
var payload = TypeConversion.ConvertTo<MyDto>("""{"Name":"abc","Count":3}""");

// Spans (span-native parsing on net10, ToString fallback on netstandard2.0)
long ticks = TypeConversion.ConvertTo<long>("637500000000000000".AsSpan());

// Booleans — lenient tokens: true/t/1/y/yes/on and false/f/0/n/no/off (case-insensitive)
bool on = TypeConversion.ToBoolean("yes");
bool ok = TypeConversion.TryToBoolean("enabled", out var b, trueValues: ["enabled"], falseValues: ["disabled"]);

// JsonElement (strict typed accessors; ConvertTo handles lenient token coercion)
object? loose = TypeConversion.FromJsonElement(element); // string/long/double/bool/null/list
bool got = TypeConversion.TryFromJsonElement<int>(element, out var n);

// Enums / sequences
var status = TypeConversion.EnumOrDefault("Active", StatusEnum.Unknown);
var maybe = TypeConversion.EnumOrNull<StatusEnum>(raw);
var values = TypeConversion.ToEnumerable(scalarOrArrayOrJson); // always a sequence
int[] bulk = TypeConversion.ConvertToArray<int>(values)!;

Conversion

TypeConversion.Logger = loggerFactory.CreateLogger("TypeConversion");

Pathing

using Lyo.Common.Pathing;

var root = "/mem/lyo";
var child = PathHelpers.Combine(PathStyle.Posix, root, "session", "file.txt");
var full = PathHelpers.GetFullPath(PathStyle.Posix, child);
PathHelpers.ThrowIfEscapesRoot(PathStyle.Posix, root, full);

Identifier matrix

Generator Sortable Length Notes
Ksuid (time-prefix) 27 chars (base62) Drop-in monotonic-ish id; good URL safety.
LyoGuid (sequential) 36 chars (GUID) UUID v7-style for DB index locality.
NanoId configurable (default 21) URL-safe random; collision rates documented per length.
Snowflake int64 Configurable worker + datacenter ids.
Ulid 26 chars (Crockford base32) ULID spec.
AutoIncrementIdGenerator int64 Pure in-process counter for tests / fixtures.

Records / metadata

FileTypeInfo is the canonical registry for Lyo file types: human-readable name, canonical extensions (e.g. .ag, .chacha, .ag2k), two-key envelope suffix ( TwoKeyEnvelopeSuffix = "2k"), and CommonStorageResolutionSuffixes (used by Lyo.FileStorage to resolve persisted blobs when explicit metadata isn't present).

JSON

LyoJsonSerializerOptions is the shared default JsonSerializerOptions. The converters under JsonConverters/ (e.g. enum-as-string fallbacks, raw JSON pass-through) are pre-registered so other Lyo packages can reuse them without duplicating wiring.

Conversion

Lyo.Common.Conversion.TypeConversion is the central type-conversion engine used across the Lyo suite (API patch binding, query filters, web-component grids, message-queue envelopes). It converts CLR objects, strings, character spans, and JsonElement values to target types — nullable unwrapping, enums (name or numeric), Guid/date/time parsing, and collection materialization (T[], List<T>, HashSet<T>, IReadOnlyList<T>, ISet<T>, any concrete collection with an IEnumerable<T> constructor).

Failures throw TypeConversionException (derives InvalidOperationException) carrying Value, SourceType, and TargetType. Hook up logging by assigning the static logger — Debug on success, Warning on Try* misses, Error before throws (all zero-allocation via LoggerMessage.Define and disabled by default with NullLogger):

TypeConversionExtensions adds the reflection helpers the engine uses: IsNumericType(), IsNullable(), IsCollectionType(), GetCollectionElementType(), GetFriendlyTypeName(), IsObjectEnumerable(), and TryGetAsEnumerable<T>().

Dependencies

Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).

  • Lyo.Exceptions — (direct, lyo)
  • Microsoft.Extensions.Logging.Abstractions 10.0.5 — (direct, microsoft)
  • System.Memory 4.6.3 — (direct, microsoft, netstandard2.0)
  • System.Text.Json 10.0.5 — (direct, microsoft, netstandard2.0)
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (73)

Showing the top 5 NuGet packages that depend on Lyo.Common:

Package Downloads
Lyo.DateAndTime

Date and time utilities and services for the Lyo library suite.

Lyo.Api.Models

API models and data transfer objects for the Lyo API library suite.

Lyo.KeyStore

Key management interface and local implementation for encryption key storage, versioning, and rotation.

Lyo.PackageMetadata

Multi-ecosystem package catalog types and IPackageMetadataStore for stack traces and persistence adapters.

Lyo.Encryption

A production-ready .NET encryption library providing secure, authenticated encryption with support for multiple algorithms (AES-GCM, ChaCha20Poly1305, RSA), key management, and envelope encryption patterns.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 561 8/16/2026