CSharpEssentials.Core
6.5.2
dotnet add package CSharpEssentials.Core --version 6.5.2
NuGet\Install-Package CSharpEssentials.Core -Version 6.5.2
<PackageReference Include="CSharpEssentials.Core" Version="6.5.2" />
<PackageVersion Include="CSharpEssentials.Core" Version="6.5.2" />
<PackageReference Include="CSharpEssentials.Core" />
paket add CSharpEssentials.Core --version 6.5.2
#r "nuget: CSharpEssentials.Core, 6.5.2"
#:package CSharpEssentials.Core@6.5.2
#addin nuget:?package=CSharpEssentials.Core&version=6.5.2
#tool nuget:?package=CSharpEssentials.Core&version=6.5.2
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/IsBetweenExclusivefor anyIComparable<T>. - Functional Extensions: Null-safe execution (
IfNotNull,IfNull,IfTrue,IfFalse),IsNull/IsNotNull, stringIsEmpty/IsNotEmpty. - Task Helpers:
WithCancellation(forTask,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
intconstants (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 | 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 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. |
-
.NETStandard 2.0
- System.Memory (>= 4.5.5)
- System.Threading.Tasks.Extensions (>= 4.5.4)
-
.NETStandard 2.1
- No dependencies.
-
net10.0
- No dependencies.
-
net11.0
- No dependencies.
-
net9.0
- No dependencies.
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 | 125 | 10/10/2026 |
| 6.5.1 | 145 | 10/10/2026 |
| 6.5.0 | 141 | 10/9/2026 |
| 6.4.0 | 160 | 10/9/2026 |
| 6.3.0 | 186 | 10/8/2026 |
| 6.2.0 | 254 | 10/8/2026 |
| 6.1.0 | 271 | 10/7/2026 |
| 6.0.0 | 300 | 10/7/2026 |
| 5.2.1 | 308 | 10/7/2026 |
| 5.2.0 | 320 | 10/7/2026 |
| 5.1.0 | 334 | 10/7/2026 |
| 5.0.0 | 407 | 10/6/2026 |
| 4.1.0 | 420 | 10/6/2026 |
| 4.0.0 | 482 | 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 | 526 | 5/20/2026 |