Lyo.Common
1.0.6
dotnet add package Lyo.Common --version 1.0.6
NuGet\Install-Package Lyo.Common -Version 1.0.6
<PackageReference Include="Lyo.Common" Version="1.0.6" />
<PackageVersion Include="Lyo.Common" Version="1.0.6" />
<PackageReference Include="Lyo.Common" />
paket add Lyo.Common --version 1.0.6
#r "nuget: Lyo.Common, 1.0.6"
#:package Lyo.Common@1.0.6
#addin nuget:?package=Lyo.Common&version=1.0.6
#tool nuget:?package=Lyo.Common&version=1.0.6
Lyo.Common
Shared primitives: ID generators, file/MIME/language/HTTP/file-size metadata, geometry, secure RNG, typed extensions, and shared System.Text.Json options.
Note. Earlier versions of this README also described
Ensure,Error,ErrorBuilder, andResult*types. Those live inLyo.Result, not here.Lyo.Commonhas no dependency on results.
Features
- ID generators (
Identifiers/).Ksuid,LyoGuid,NanoId,Snowflake,Ulid, andAutoIncrementIdGeneratorfor 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, implicitint),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 skip a copy when the source is already the right shape.Utilities. Shared helpers:SafeDispose, file-size conversions, expression-based property-path extraction.- Pathing (
Pathing/).PathStyle(Host/Posix) andPathHelpersfor 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. Other Lyo packages use this instead ofSystem.Randomfor security-adjacent work. Disposable. Base class and lambda disposable.HashCodeHelpers.HashCode.Combine-style helpers fornetstandard2.0.LyoJsonSerializerOptions. SharedJsonSerializerOptions(case-insensitive, ignore-null, enum-as-string) plus converters inJsonConverters/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 converts CLR objects, strings, character spans, and JsonElement values to target types. Callers include API patch binding, query filters, web-component grids, and message-queue
envelopes. It unwraps nullables, parses enums (name or numeric), Guid/date/time, and materializes collections (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. Assign the static logger to get
Debug on success, Warning on Try* misses, and Error before throws. Logging is zero-allocation via LoggerMessage.Define and off by default (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.Abstractions10.0.5(direct, microsoft)System.Memory4.6.3(direct, microsoft, netstandard2.0)System.Text.Json10.0.5(direct, microsoft, netstandard2.0)
| Product | Versions 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. |
-
.NETStandard 2.0
- Lyo.Exceptions (>= 1.0.6)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
- System.Memory (>= 4.6.3)
- System.Text.Json (>= 10.0.5)
-
net10.0
- Lyo.Exceptions (>= 1.0.6)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.5)
NuGet packages (75)
Showing the top 5 NuGet packages that depend on Lyo.Common:
| Package | Downloads |
|---|---|
|
Lyo.Result
Result, Error, Option, and validation primitives for the Lyo library suite. |
|
|
Lyo.Hashing
Digests, hex encoding, hashing streams, non-cryptographic checksums (CRC/Adler), lightweight file fingerprints (non-security), and optional hashing service. |
|
|
Lyo.Api.Models
API models and data transfer objects for the Lyo API library suite. |
|
|
Lyo.DateAndTime
Date and time utilities and services for the Lyo library suite. |
|
|
Lyo.Query.Models
Query models for building and representing queries - QueryNode, QueryRequest, ConditionNode, SortBy, builders. Shared by Lyo.Query and Lyo.Api. |
GitHub repositories
This package is not used by any popular GitHub repositories.