CSharpEssentials.Core 6.5.2

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

CSharpEssentials.Core

Foundational utilities and extensions for everyday .NET development. Zero internal dependencies.

Features

  • String Conversions: Pascal, Camel, Snake, Kebab, Macro, Train, Title, UnderscoreCamel.
  • Collection Helpers: Conditional add and filter, null filtering, random selection, set comparison, AllTrue / AllFalse.
  • Range Checks: IsBetween / IsBetweenExclusive for any IComparable<T>.
  • Functional Extensions: Null-safe execution (IfNotNull, IfNull, IfTrue, IfFalse), IsNull / IsNotNull, string IsEmpty / IsNotEmpty.
  • Task Helpers: WithCancellation (for Task, Task<T>, ValueTask, ValueTask<T>), AsTask, AsValueTask.
  • GUID Utilities: URL-safe Base64 encoding, Version 7 GUID generation on .NET 9+.
  • Exception Helpers: Flatten inner exceptions and messages.
  • HTTP Constants: Common status codes as int constants (HttpCodes).
  • Transaction Abstraction: ITransactionRunner, implemented by data-access packages.

Installation

dotnet add package CSharpEssentials.Core

Targets net11.0, net10.0, net9.0, netstandard2.1 and netstandard2.0.

Usage

String Case Conversions

using CSharpEssentials.Core;

string text = "helloWorld";

text.ToPascalCase();          // "HelloWorld"
text.ToCamelCase();           // "helloWorld"
text.ToSnakeCase();           // "hello_world"
text.ToKebabCase();           // "hello-world"
text.ToMacroCase();           // "HELLO_WORLD"
text.ToTrainCase();           // "Hello-World"
text.ToTitleCase();           // "Hello World"
text.ToUnderscoreCamelCase(); // "_helloWorld"

Collection Extensions

var list = new List<string> { "a", "b" };

list.IfAdd(true, "c");
list.IfAddRange(true, ["d", "e"]);

IEnumerable<string> source = list;
source.ForEach(Console.WriteLine).ToList();

var filtered = list.WhereIf(true, x => x != "a");
var clean = new List<string?> { "a", null, "b" }.WithoutNulls();

var numbers = new[] { 1, 2, 3 };
numbers.GetRandomItem();
numbers.GetRandomItems(2);

new List<string> { "a", "b" }.HasSameElements(["b", "a"]);  // true (order and duplicates ignored)
new[] { true, true }.AllTrue();                                // true
new[] { false, false }.AllFalse();                             // true

ForEach on IEnumerable<T> is lazy: it runs the action for each item while the result is enumerated, so nothing happens until you iterate it (for example with ToList()). On a List<T> the built-in List<T>.ForEach is chosen instead. GetRandomItem and GetRandomItems use RandomNumberGenerator, pick unique items and work on T[], List<T> and Span<T>.

Range Checks

5.IsBetween(1, 10);            // true  (inclusive)
10.IsBetweenExclusive(1, 10);  // false (exclusive)
orderDate.IsBetween(start, end);

Functional Extensions

object? data = GetData();

if (data.IsNull()) { /* ... */ }
if (data.IsNotNull()) { /* ... */ }

data.IfNotNull(d => Process(d));
data.IfNull(() => Initialize());

string? name = null;
name.IsEmpty();      // true for null, "" and whitespace
name.IsNotEmpty();   // false

Each IfNotNull / IfNull overload returns a bool: whether the value was not null (IfNotNull) or null (IfNull). IfNotNull and IfNull also take an else action:

data.IfNotNull(d => Process(d), () => Initialize());
data.IfNull(() => Initialize(), d => Process(d));

true.IfTrue(() => Console.WriteLine("yes"));
false.IfFalse(() => Console.WriteLine("no"));

Task Helpers

await SomeTask().WithCancellation(cts.Token);

string value = "hello";
Task<string> task = value.AsTask();
ValueTask<string> vt = value.AsValueTask();

WithCancellation stops waiting and throws OperationCanceledException when the token is cancelled. It does not cancel the underlying task, and it returns the original task when the token cannot be cancelled.

GUID Utilities

Guid id = Guider.NewGuid();          // Version 7 on .NET 9+
string shortId = id.ToStringFromGuid(); // URL-safe Base64 (22 chars)
Guid parsed = shortId.ToGuidFromString();

Guider.ToStringFromGuid and Guider.ToGuidFromString are the static forms of the same two conversions. See Guids.

Exception Helpers

try { /* ... */ }
catch (Exception ex)
{
    var innerExceptions = ex.GetInnerExceptions();
    var messages = ex.GetInnerExceptionsMessages();
}

Both return lazy sequences that start with ex itself, followed by each inner exception.

HTTP Status Codes

int ok = HttpCodes.Ok;
int notFound = HttpCodes.NotFound;
int badRequest = HttpCodes.BadRequest;

Other Helpers

object boxed = 42;
int number = boxed.ExplicitCast<int>();

DateTime when = 1700000000000L.MsToDateTime();   // Unix milliseconds

HttpGroup group = HttpStatus.BadRequest.GetTypeGroup<HttpGroup, HttpStatus>();  // HttpGroup.ClientError

public enum HttpStatus { Ok = 200, BadRequest = 400 }
public enum HttpGroup { Success = 200, ClientError = 400 }

GetTypeGroup rounds the enum value down to a multiple of group (default 100) and converts it to the target enum.

On .NET 10 and later, using CSharpEssentials; also brings the C# 14 extension members IEnumerable<T>.IsEmpty (property, !source.Any()) and string.IsPalindrome (property).

Transaction Runner Abstraction

ITransactionRunner (namespace CSharpEssentials.Transactions) runs a unit of work in a transaction and commits only when shouldCommit returns true. It has no dependencies, so data-access packages implement it (EfCoreTransactionRunner<TDbContext> in CSharpEssentials.EntityFrameworkCore) and pipelines consume it (TransactionBehavior in CSharpEssentials.Mediator).

using CSharpEssentials.ResultPattern;
using CSharpEssentials.Transactions;

Result result = await transactionRunner.ExecuteAsync(
    ct => handler.Handle(command, ct),
    outcome => outcome.IsSuccess,
    cancellationToken);

Here handler.Handle returns ValueTask<Result>; Result comes from CSharpEssentials.Results.

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 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 is compatible. 
.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 (6)

Showing the top 5 NuGet packages that depend on CSharpEssentials.Core:

Package Downloads
CSharpEssentials.Errors

Comprehensive error handling system for functional programming in C#. Provides Error types, ErrorMetadata, ErrorType enums, and extensions for robust error management. Foundation for Result pattern and functional error handling.

CSharpEssentials

A comprehensive C# library enhancing functional programming capabilities with type-safe monads (Maybe, Result), discriminated unions (Any), and robust error handling. Features include: domain-driven design support, enhanced Entity Framework integration, testable time management, JSON utilities, and LINQ extensions. Built for modern C# development with focus on maintainability, testability, and functional programming principles.

CSharpEssentials.EntityFrameworkCore

Enhances Entity Framework Core with functional programming patterns and DDD-friendly features. Includes base entity classes, soft delete support, audit trails, query filters, optimistic concurrency, PostgreSQL integration, query performance monitoring, and domain event handling. Perfect for building maintainable and scalable data access layers in modern .NET applications.

CSharpEssentials.GcpSecretManager

A powerful .NET configuration provider for Google Cloud Secret Manager that enables seamless secret management in your applications. Features include region-specific secret handling, flexible filtering options, batch processing, automatic secret rotation, built-in retry policies, and JSON value flattening support. Perfect for cloud-native applications requiring secure and scalable secret management.

CSharpEssentials.Rules

Business rules engine for domain-driven design in C#. Provides rule validation, business logic enforcement, and domain rule composition patterns. Essential for implementing complex business rules in a maintainable way.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.5.2 73 10/10/2026
6.5.1 92 10/10/2026
6.5.0 86 10/9/2026
6.4.0 107 10/9/2026
6.3.0 134 10/8/2026
6.2.0 209 10/8/2026
6.1.0 226 10/7/2026
6.0.0 255 10/7/2026
5.2.1 264 10/7/2026
5.2.0 275 10/7/2026
5.1.0 289 10/7/2026
5.0.0 362 10/6/2026
4.1.0 395 10/6/2026
4.0.0 457 10/5/2026
3.2.3 718 5/31/2026
3.2.2 601 5/31/2026
3.2.1 570 5/31/2026
3.2.0 571 5/30/2026
3.1.0 557 5/27/2026
3.0.8 524 5/20/2026
Loading failed