CSharpHelperExtensions 1.1.0

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

CSharpHelperExtensions

A set of commonly used C# extension methods that reduce boilerplate across four focused namespaces: value checks, string manipulation, collection operations, and dictionary helpers.

.NET

Installation

dotnet add package CSharpHelperExtensions

Namespaces

Import the namespace for the extensions you need:

Namespace What it covers
CSharpHelperExtensions.Values In, IsBetween, ToJson
CSharpHelperExtensions.Strings All string extensions
CSharpHelperExtensions.Enumerable All IEnumerable<T> and collection extensions
CSharpHelperExtensions.Dictionaries All IDictionary<TKey,TValue> extensions

Interactive Samples

The sample/ folder contains three .NET Interactive notebooks you can run directly in VS Code (with the Polyglot Notebooks extension) or Jupyter.

Each notebook loads the compiled DLL and imports the relevant namespace in its Setup cell — run that cell first, then run any section independently.

Notebook Namespace What it covers
sample/value-extensions.ipynb CSharpHelperExtensions.Values In, IsBetween (all four BetweenComparison modes), ToJson, and chaining examples
sample/string-extensions.ipynb CSharpHelperExtensions.Strings All 50+ string methods grouped by category: null-safety, parsing, transformation, whitespace, comparisons, prefix/suffix, encoding, and chaining pipelines
sample/enumerable-extension.ipynb CSharpHelperExtensions.Enumerable All collection methods: presence checks, materialization, async projection, partitioning, batching, conditional mutation, and chaining pipelines
sample/dictionary-extensions.ipynb CSharpHelperExtensions.Dictionaries All dictionary methods: safe lookup, add-if-missing, merging, bulk add, in-place filtering, read-only views, and chaining pipelines

Usage

Values

using CSharpHelperExtensions.Values;

// Membership check — like SQL IN
"admin".In("admin", "superadmin");          // true
HttpMethod.Post.In(Post, Put, Patch);       // true

// Range check — inclusive by default
5.IsBetween(1, 10);                         // true
1.IsBetween(1, 10, BetweenComparison.ExcludeBoth);  // false

// JSON serialisation via Newtonsoft.Json
new { Name = "Alice", Age = 30 }.ToJson();              // {"Name":"Alice","Age":30}
new { Name = "Alice" }.ToJson(indentation: true);        // pretty-printed

Strings

using CSharpHelperExtensions.Strings;

// Null-safety
"  ".IsNullOrEmpty();                       // true (checks whitespace)
"hello".HasValue();                         // true
((string)null).OrDefault("N/A");            // "N/A"

// Transformation
"  Hello World  ".TrimToLower();            // "hello world"
"café au lait".ToSlug();                    // "cafe-au-lait"
"4111111111111234".MaskStart(4);            // "************1234"

// Safe parsing — returns null instead of throwing
"42".ToIntOrNull();                         // 42
"abc".ToIntOrNull();                        // null

// Comparisons
"Hello".EqualsIgnoreCase("HELLO");          // true
"path/".EnsurePrefix("/");                  // "/path/"
"report.csv".TrimSuffix(".csv");            // "report"

// Encoding
"Hello".Base64Encode();                     // "SGVsbG8="
"Hello".ToBase64Url();                      // URL-safe, no padding chars

Enumerable

using CSharpHelperExtensions.Enumerable;

// Null-safe presence checks
list.HasAny();                              // non-null and non-empty
list.None();                                // null or empty
list.OrEmpty();                             // null → empty sequence

// Filtering
items.WhereNotNull();                       // removes null elements
strings.CleanNullOrEmptyItems();            // removes null, empty, and whitespace strings

// Async projection with optional concurrency cap
var results = await ids.SelectAsync(FetchAsync, maxParallel: 4);

// Splitting
var (passed, failed) = scores.Partition(s => s >= 60);
var batches = items.Batch(100);             // process in chunks

// Conditional building — fluent, returns same list
var tags = new List<string>()
    .AddIf(isPremium, "premium")
    .AddIf(isAdmin, "admin");

// Min/Max that return default instead of throwing on empty
people.MinByOrDefault(p => p.Age);
people.MaxByOrDefault(p => p.Age);

// Utilities
42.Yield();                                 // wrap a single value as IEnumerable<T>
items.WithIndex();                          // (Index, Item) tuples
names.JoinAsString(", ");                   // fluent string.Join

Dictionaries

using CSharpHelperExtensions.Dictionaries;

// Safe lookup — returns default instead of throwing on missing key or null dict
DictionaryExtensions.GetValueOrDefault(dict, "key");    // value or default(TValue)

// Add-if-missing — factory only called when key is absent
cache.GetOrAdd("user:1", key => LoadFromDb(key));       // existing or newly stored value

// Merge two dictionaries — overwrite:false keeps existing values (default)
defaults.Merge(overrides, overwrite: true);             // returns same dict for chaining

// Bulk add from any IEnumerable<KeyValuePair>
inventory.AddRange(incomingItems);                      // returns same dict for chaining

// Filter in-place by key predicate
config.RemoveWhere(k => k.StartsWith("internal."));     // returns same dict for chaining

// Expose as a live read-only view
IReadOnlyDictionary<string, int> view = DictionaryExtensions.AsReadOnly(dict);
Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 81 5/31/2026
1.0.0 89 5/29/2026