CSharpEssentials.Core 3.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package CSharpEssentials.Core --version 3.0.2
                    
NuGet\Install-Package CSharpEssentials.Core -Version 3.0.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="3.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CSharpEssentials.Core" Version="3.0.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 3.0.2
                    
#r "nuget: CSharpEssentials.Core, 3.0.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@3.0.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=3.0.2
                    
Install as a Cake Addin
#tool nuget:?package=CSharpEssentials.Core&version=3.0.2
                    
Install as a Cake Tool

CSharpEssentials.Core

CSharpEssentials.Core is the foundational package of the CSharpEssentials ecosystem. It provides a rich set of extension methods, utilities, and constants designed to simplify common programming tasks in .NET applications. This library focuses on improving code readability, reducing boilerplate, and providing high-performance utilities for daily development.

🚀 Features

  • Advanced Collection Extensions: Fluent methods for conditional additions, filtering, and null handling.
  • String Manipulations: Comprehensive case conversion utilities (Pascal, Camel, Kebab, Snake, etc.).
  • Functional-Style Extensions: IfTrue, IfNull, IfNotNull extensions to write cleaner, more expressive code.
  • Task Extensions: Simplified WithCancellation support for Task and ValueTask.
  • Optimized GUID Utilities: High-performance, URL-friendly Base64 string conversions for GUIDs and Version 7 GUID generation.
  • Randomization: Extensions for retrieving random items from collections and arrays.
  • Exception Handling: Utilities to flatten and retrieve inner exceptions.
  • Constants: Standard HTTP status codes available as constants.

📦 Installation

dotnet add package CSharpEssentials.Core

🛠 Usage

1. String Extensions (Case Conversion)

Convert strings between various naming conventions easily.

using CSharpEssentials.Core;

string text = "helloWorld";

string pascal = text.ToPascalCase();          // "HelloWorld"
string kebab = text.ToKebabCase();            // "hello-world"
string snake = text.ToSnakeCase();            // "hello_world"
string macro = text.ToMacroCase();            // "HELLO_WORLD"
string train = text.ToTrainCase();            // "Hello-World"
string title = text.ToTitleCase();            // "Hello World"
string underscoreCamel = text.ToUnderscoreCamelCase(); // "_helloWorld"

// All case conversions support optional CultureInfo
string turkish = text.ToPascalCase(new CultureInfo("tr-TR"));

2. Collection Extensions

Simplify list and enumerable operations.

using CSharpEssentials.Core;

var list = new List<string> { "Apple", "Banana" };

// Conditional Add
list.IfAdd(condition: true, "Cherry");

// Conditional AddRange
list.IfAddRange(condition: true, "Date", "Elderberry");

// Fluent ForEach
list.ForEach(item => Console.WriteLine(item));

// Conditional Where (Clean LINQ)
var filtered = list.WhereIf(condition: true, item => item.StartsWith("A"));

// Remove Nulls safely
var nullableList = new List<string?> { "A", null, "B" };
var cleanList = nullableList.WithoutNulls(); // ["A", "B"]

3. Functional & Logical Extensions

Reduce if statements and improve flow control visibility.

using CSharpEssentials.Core;

object? data = GetSomeData();

// Null Checks
if (data.IsNull()) { /* handle null */ }
if (data.IsNotNull()) { /* handle data */ }

// Functional 'If' Execution
data.IfNotNull(d => Process(d));
data.IfNull(() => InitializeDefaults());

data.IfNotNull(
    action: d => Log("Data exists"),
    elseAction: () => Log("Data is missing")
);

bool isValid = true;
isValid.IfTrue(() => Console.WriteLine("Valid!"));
isValid.IfFalse(() => Console.WriteLine("Invalid!"));

4. Task & Async Extensions

Easily add cancellation support to tasks.

using CSharpEssentials.Core;

CancellationTokenSource cts = new();

// Safe cancellation handling
await SomeLongRunningTask().WithCancellation(cts.Token);

5. GUID Utilities

Work with GUIDs more efficiently, especially for APIs and URLs.

using CSharpEssentials.Core;

// Generate New Version 7 GUID (Time-ordered)
Guid newId = Guider.NewGuid();

// Convert to URL-safe Base64 string (Shorter than standard Guid string)
string urlFriendlyId = newId.ToStringFromGuid(); 

// Convert back from URL-safe string
Guid parsedId = urlFriendlyId.ToGuidFromString();

6. Random Extensions

Pick random items from collections or arrays efficiently.

using CSharpEssentials.Core;

var numbers = new [] { 1, 2, 3, 4, 5 };

int randomItem = numbers.GetRandomItem();
int[] randomSubset = numbers.GetRandomItems(3);

7. Exception Extensions

Flatten nested exceptions to get to the root cause or collect all messages.

using CSharpEssentials.Core;

try 
{
    // ... code that throws nested exceptions
}
catch (Exception ex)
{
    // Get all inner exceptions
    IEnumerable<Exception> allExceptions = ex.GetInnerExceptions();

    // Get all messages
    IEnumerable<string?> messages = ex.GetInnerExceptionsMessages();
}

🧩 Dependencies

CSharpEssentials.Core has zero dependencies on other packages, making it extremely lightweight and safe to include in any project.

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

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.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.Any

Discriminated union types (Any<T0,T1> to Any<T0,...,T7>) for functional programming in C#. Provides type-safe alternatives to object/dynamic with pattern matching, implicit conversions, and JSON serialization support. Essential for functional programming patterns and type-safe handling of multiple possible types.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.4 81 5/6/2026
3.0.3 161 5/5/2026
3.0.2 257 5/5/2026
3.0.1 324 5/3/2026
3.0.0 325 5/3/2026
2.1.0 375 11/26/2025
2.0.9 332 9/30/2025
2.0.8 323 9/29/2025
2.0.7 309 9/29/2025
2.0.6 305 9/29/2025
2.0.5 312 9/29/2025
2.0.4 318 9/28/2025
2.0.3 313 9/28/2025
2.0.2 317 9/28/2025
2.0.1 304 9/28/2025
2.0.0 324 9/28/2025