Linger.Utils
2.0.0-preview.5
dotnet add package Linger.Utils --version 2.0.0-preview.5
NuGet\Install-Package Linger.Utils -Version 2.0.0-preview.5
<PackageReference Include="Linger.Utils" Version="2.0.0-preview.5" />
<PackageVersion Include="Linger.Utils" Version="2.0.0-preview.5" />
<PackageReference Include="Linger.Utils" />
paket add Linger.Utils --version 2.0.0-preview.5
#r "nuget: Linger.Utils, 2.0.0-preview.5"
#:package Linger.Utils@2.0.0-preview.5
#addin nuget:?package=Linger.Utils&version=2.0.0-preview.5&prerelease
#tool nuget:?package=Linger.Utils&version=2.0.0-preview.5&prerelease
Linger.Utils
Current branch migration guide · Archived 2.0.0-preview.4 guide
Linger.Utils is a .NET utility library for everyday development. It provides extension methods and helper classes for strings, numbers, dates, collections, files, DataTables, encryption, and argument validation. The core API stays lightweight and supports multiple target frameworks; runtime reflection and expression-tree features are provided by the optional Linger.Reflection package.
For complete examples, behavior rules, and compatibility notes, see the detailed usage guide.
Feature overview
- Strings and type conversion: Validation, splitting, truncation, formatting, and predictable conversion of numbers and common types
- Date and time: Age calculation, range checks, date boundaries, and type conversion
- Collections and data: Paging, iteration, joins, DataTable mapping, and delimited strings
- Files and paths: File and directory operations, copying, moving, deletion, and cross-platform path handling
- Security and reliability: Authenticated encryption, retry policies, GUID utilities, and argument validation
- Compatibility: Selected BCL APIs for older target frameworks and explicit mapping APIs for AOT-friendly code
Installation
dotnet add package Linger.Utils --version 2.0.0-preview.4
Supported target frameworks:
- .NET 11.0
- .NET 10.0
- .NET 9.0
- .NET 8.0
- .NET Standard 2.0
- .NET Framework 4.7.2
Quick start
Strings and type conversion
using Linger.Extensions.Core;
string value = "123";
int number = value.ToIntOrDefault();
int? nullableNumber = value.ToIntOrNull();
bool isEmail = "user@example.com".IsEmail();
string[] columns = "id,name,email".SplitToArray(',');
string shortened = "a long piece of text".Truncate(10);
ToIntOrDefault, ToIntOrNull, and TryToInt use a conservative decimal-to-integer policy: conversion succeeds only when the fractional part is zero and the value is within the target type's range. Use ToSplitList(string) for regular-expression delimiters; prefer SplitToArray or SplitToList for literal delimiters.
Dates, GUIDs, and enums
using Linger.Extensions.Core;
DateTime birthDate = new(1990, 5, 15);
int age = birthDate.CalculateAge();
bool inRange = DateTime.Now.InRange(DateTime.Today, DateTime.Today.AddDays(7));
Guid? id = null;
bool isEmpty = id.IsNullOrEmpty();
string generatedId = GuidCode.NewId;
enum Status
{
Active
}
Status status = "Active".GetEnum<Status>();
Use StartOfDay, EndOfDay, StartOfMonth, and EndOfMonth for date boundaries. DateTime extensions also provide conversions among DateOnly, TimeOnly, and DateTime.
Files and paths
using Linger.Extensions.IO;
using Linger.Helper;
FileHelper.CreateFile("data.txt", "Hello World");
if (FileHelper.TryReadText("data.txt", out string content))
{
Console.WriteLine(content);
}
FileHelper.CopyFile("source.txt", "backup/dest.txt");
FileHelper.DeleteFileIfExists("temp.txt");
// CopyDir rejects existing directory links and junctions in the destination path.
FileHelper.CopyDir("sourceFolder", "backupFolder");
FileHelper.ClearDirectory("temp");
string normalized = PathHelper.CleanAndNormalizePureString(
@"temp\\folder//file.txt\\",
preserveEndingSeparator: false);
bool hasInvalidChars = "file<name>.txt".ContainsInvalidPathChars();
Collections and joins
using Linger.Extensions.Collection;
var values = new List<int> { 1, 2, 3, 4, 5 };
var page = values.Paging(pageIndex: 2, pageSize: 2);
string text = values.ToSeparatedString(", ");
values.ForEach(Console.WriteLine);
var left = employees.LeftJoin(
departments,
employee => employee.DepartmentId,
department => department.Id,
(employee, department) => new
{
Employee = employee.Name,
Department = department?.Name ?? "No department"
});
LeftJoin, RightJoin, and FullJoin use BCL implementations on newer target frameworks and conditional compatibility implementations on older targets. The tuple-returning LeftJoin overload remains provided by Linger.
DataTable mapping
using Linger.Extensions.Data;
DataTable? table = GetDataTable();
List<UserDto>? users = table.ToList(row => new UserDto
{
Id = Convert.ToInt32(row["Id"]),
Name = row["Name"]?.ToString()
});
The explicit mapper above does not use reflection and is suitable for trimming and Native AOT. Property-based automatic mapping is provided by Linger.Reflection.
Objects, arrays, and enums
using Linger.Extensions.Core;
object value = "123";
int number = value.ToIntOrDefault();
int[] numbers = new[] { 1, 2, 3 };
numbers.ForEach((item, index) => Console.WriteLine($"{index}: {item}"));
Status status = 1.GetEnum<Status>();
string name = 1.GetEnumName<Status>();
Reading DescriptionAttribute and DisplayAttribute belongs to Linger.Reflection; basic enum parsing and numeric conversion are provided by Linger.Utils.
Authenticated encryption
using Linger.Extensions.Core;
string plaintext = "Sensitive data";
string encrypted = plaintext.AesEncryptAuthenticated(key);
string decrypted = encrypted.AesDecryptAuthenticated(key);
Authenticated encryption derives keys with PBKDF2-HMAC-SHA256 (600,000 iterations, recorded in the payload header), uses a random salt and IV, and verifies ciphertext integrity with HMAC-SHA256. Each call costs about six times as much as the previous 100,000-iteration format: a fraction of a second on .NET 8 and later, and often several seconds on .NET Framework depending on the hardware. Store production keys in a dedicated key-management service; legacy ciphertext can still be read with the obsolete AesDecrypt, which is intended only for migration.
Retries and cancellation
using Linger.Helper;
var options = new RetryOptions
{
MaxRetryAttempts = 3,
DelayMilliseconds = 1000,
UseExponentialBackoff = true,
MaxDelayMilliseconds = 30000
};
var retry = new RetryHelper(options);
var result = await retry.ExecuteAsync(
ct => SendRequestAsync(ct),
"Network request",
shouldRetry: exception => exception is HttpRequestException or TimeoutException,
cancellationToken: cancellationToken);
Pass a CancellationToken through asynchronous operations. Retryable exceptions must be selected explicitly with shouldRetry; omitting the predicate does not retry exceptions automatically.
Argument validation
public void ProcessData(string data, IEnumerable<int> values)
{
ArgumentNullException.ThrowIfNull(data);
ArgumentException.ThrowIfNullOrWhiteSpace(data);
ArgumentNullException.ThrowIfNull(values);
}
Linger.Utils uses these BCL APIs internally on every target framework. Its compatibility copies for .NET Standard 2.0 and .NET Framework 4.7.2 are internal and are not exposed, so code that targets those frameworks must supply its own polyfills or use GuardExtensions.
Feature index
| Feature | Main APIs or types |
|---|---|
| Strings | StringExtensions, SplitToArray, SplitToList, ToSplitList |
| Numeric and object conversion | ToXxx, ToXxxOrNull, ToXxxOrDefault, TryToXxx |
| Date and time | DateTimeExtensions (including DateOnly and TimeOnly conversion) |
| Collections and arrays | IEnumerableExtensions, ListExtensions, ArrayExtensions |
| DataTable | Explicit mapper and factory APIs in DataTableExtensions |
| Files and paths | FileHelper, PathHelper, PathExtensions |
| Encryption | AesEncryptAuthenticated, AesDecryptAuthenticated (not available in the .NET Standard 2.0 build) |
| GUIDs and enums | GuidCode, GUID extensions, EnumExtensions |
| Retries | RetryHelper, RetryOptions |
| Argument validation | ThrowIfNull, ThrowIfNullOrEmpty, ThrowIfNullOrWhiteSpace |
Optional features
Linger.Reflection
Install it when runtime metadata or expression trees are required:
dotnet add package Linger.Reflection --version 2.0.0-preview.4
The package provides expression composition, dynamic IQueryable ordering, runtime property access, enum attribute reading, and reflection-based IEnumerable<T>.ToDataTable() and DataTable.ToList<T>(). These APIs are not suitable for Native AOT or trimming-sensitive paths.
Linger.Json
Install Linger.Json when System.Text.Json converters, DataTable JSON conversion, or JsonDefaults are required. See the Linger.Json documentation.
Compatibility and design conventions
- On .NET 10 and later, prefer the framework
LeftJoinandRightJoinimplementations; on .NET 11 and later, prefer the frameworkFullJoinimplementation. - .NET Standard 2.0 and .NET Framework 4.7.2 builds compile
internalpolyfills for argument validation, hashing, hexadecimal conversion, and nullable annotations. They are implementation details and are not exposed to consuming projects. - For Native AOT or trimming, prefer explicit mapper/factory APIs and avoid runtime reflection.
- Numeric conversion uses lossless, low-allocation paths first; use
TryToXxxorToXxxOrDefaultfor ordinary failures instead of exceptions as control flow. - Prefer asynchronous APIs for file, network, and database I/O, and forward cancellation tokens to the underlying operation.
Dependencies
The core library keeps its dependency footprint small. System.Data.DataSetExtensions is used only for DataTable support on .NET Framework and .NET Standard 2.0.
Contributing and license
Pull requests are welcome. New features should follow the existing code style and include appropriate tests and documentation.
This project is released under the MIT license.
| 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 is compatible. 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 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. |
| .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 is compatible. 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. |
-
.NETFramework 4.7.2
- No dependencies.
-
.NETStandard 2.0
- System.Data.DataSetExtensions (>= 4.5.0)
-
net10.0
- No dependencies.
-
net11.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (13)
Showing the top 5 NuGet packages that depend on Linger.Utils:
| Package | Downloads |
|---|---|
|
Linger.FileSystem
File system abstraction library with shared asynchronous transfers and separate local synchronous and remote asynchronous capability contracts. Core library containing the base interfaces, models, and local file system implementation. |
|
|
Linger.Excel.Contracts
Core abstractions and interfaces for Excel manipulation in .NET applications. Provides a common API for Excel operations that can be implemented by various providers (ClosedXML, NPOI, etc.), with support for data conversion, styling, and template-based generation. |
|
|
Linger.Configuration
A lightweight configuration helper library for .NET applications. Simplifies access to application settings with strongly-typed configuration binding. Provides utilities for working with appsettings.json and other configuration sources. |
|
|
Linger.Email
Framework-agnostic email sending library built on MailKit. Provides SMTP transport, message composition, attachment handling, and asynchronous sending across multiple .NET frameworks. |
|
|
Linger.EFCore
An Entity Framework Core extension library providing enhanced capabilities. Includes global query filters, property conversions for complex types, and pagination utilities. Simplifies working with JSON data, collections, and complex filtering scenarios. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0-preview.5 | 122 | 11/22/2026 |
| 2.0.0-preview.4 | 139 | 11/14/2026 |
| 2.0.0-preview.3 | 134 | 9/13/2026 |
| 2.0.0-preview.1 | 172 | 8/29/2026 |
| 1.6.4 | 863 | 8/16/2026 |
| 1.6.3 | 762 | 8/5/2026 |
| 1.6.2 | 838 | 8/2/2026 |
| 1.6.0 | 870 | 7/25/2026 |
| 1.5.5 | 879 | 7/23/2026 |
| 1.5.4-preview | 813 | 7/21/2026 |
| 1.5.3-preview | 855 | 7/20/2026 |
| 1.5.2-preview | 838 | 7/19/2026 |
| 1.5.1-preview | 848 | 7/15/2026 |
| 1.5.0-preview | 853 | 7/14/2026 |
| 1.4.4-preview | 860 | 6/16/2026 |
| 1.4.3-preview | 848 | 6/15/2026 |
| 1.4.2 | 943 | 5/20/2026 |
| 1.4.1-preview | 866 | 5/12/2026 |
| 1.4.0 | 917 | 5/6/2026 |
| 1.3.3-preview | 859 | 5/5/2026 |