ktsu.Extensions 1.6.4

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

ktsu.Extensions

A comprehensive utility library of extension methods for collections, strings, dictionaries, and reflection in .NET.

License NuGet Version NuGet Version NuGet Downloads GitHub commit activity GitHub contributors GitHub Actions Workflow Status

Introduction

ktsu.Extensions is a utility library that enhances the functionality of standard .NET types through extension methods. It provides a wide range of utilities for batch operations, string manipulations, and reflection helpers, making it easier to work with common data structures and types in a consistent, null-safe manner.

Features

  • Enumerable Extensions

    • WithIndex: Enumerates over an enumerable with the index of the item
    • ToCollection: Converts an enumerable to a collection
    • ForEach: Applies an action to each element of an enumerable
    • AnyNull: Checks if the enumerable contains any null items
    • Join: Concatenates elements with a separator
    • ToStringEnumerable: Converts items to strings with null handling
    • WriteItemsToConsole: Outputs collection items to the console
  • Collection Extensions

    • AddFrom: Adds items from an enumerable to a collection
    • ReplaceWith: Replaces all items in a collection with items from an enumerable
  • Dictionary Extensions

    • GetOrCreate: Gets the value for a key or creates a new value if the key doesn't exist
    • AddOrReplace: Adds a new value or replaces an existing value
  • String Extensions

    • Ordinal comparison helpers (StartsWithOrdinal, EndsWithOrdinal, ContainsOrdinal)
    • Prefix/suffix manipulation (RemoveSuffix, RemovePrefix)
    • ReplaceOrdinal: Replaces text using ordinal comparison
    • Line ending utilities (DetermineLineEndings, NormalizeLineEndings)
    • NominalWordWrap: Best-effort word wrapping on word and hyphen boundaries for a given wrap width and nominal glyph width
  • Reflection Extensions

    • TryFindMethod: Searches for methods across inheritance hierarchies

Installation

Package Manager Console

Install-Package ktsu.Extensions

.NET CLI

dotnet add package ktsu.Extensions

Package Reference

<PackageReference Include="ktsu.Extensions" Version="x.y.z" />

Usage Examples

Enumerable Extensions

using ktsu.Extensions;

// Iterate with index
foreach (var (item, index) in myList.WithIndex())
{
    Console.WriteLine($"Item at position {index}: {item}");
}

// Apply action to each item
myList.ForEach(item => Console.WriteLine(item));

// Check for nulls
if (myList.AnyNull())
{
    Console.WriteLine("List contains null items");
}

// Join items with a separator
var items = new[] { "apple", "banana", "cherry" };
string joined = items.Join(", ");  // "apple, banana, cherry"

// Convert to string enumerable
var numbers = new[] { 1, 2, 3 };
var strings = numbers.ToStringEnumerable();  // ["1", "2", "3"]

String Extensions

using ktsu.Extensions;

string text = "Hello, World!";

// Ordinal string comparisons
if (text.StartsWithOrdinal("Hello"))
{
    Console.WriteLine("Text starts with 'Hello'");
}

// Prefix/suffix manipulation
string withoutPrefix = text.RemovePrefix("Hello, ");  // "World!"
string withoutSuffix = text.RemoveSuffix("!");        // "Hello, World"

// Line ending handling
string mixedText = "Line1\r\nLine2\nLine3";
var lineEndingStyle = mixedText.DetermineLineEndings();  // LineEndingStyle.Mixed
string normalized = mixedText.NormalizeLineEndings(LineEndingStyle.Unix);  // All \n

// Best-effort word wrap. Line length is wrapWidth / nominalGlyphWidth, so with a
// wrap width of 110 and a nominal glyph width of 10 each line holds up to 11 chars.
var lines = "the quick brown fox".NominalWordWrap(wrapWidth: 110f, nominalGlyphWidth: 10f);
// ["the quick", "brown fox"]

// Existing line breaks are honored, whitespace runs collapse, and a break may fall
// after a hyphen or at a soft hyphen (­ renders as "-" only when it wraps).
var wrapped = "context-sensitive".NominalWordWrap(wrapWidth: 90f, nominalGlyphWidth: 10f);
// ["context-", "sensitive"]

Dictionary Extensions

using ktsu.Extensions;

var cache = new Dictionary<string, List<string>>();

// Get or create a value (uses parameterless constructor)
var items = cache.GetOrCreate("key");
items.Add("item1");

// Get or create with a specific default value
var otherItems = cache.GetOrCreate("key2", new List<string> { "default" });

// Add or replace a value
cache.AddOrReplace("key3", new List<string> { "item2" });

Collection Extensions

using ktsu.Extensions;

var collection = new List<string>();

// Add multiple items at once
collection.AddFrom(new[] { "item1", "item2", "item3" });

// Replace all items in the collection
collection.ReplaceWith(new[] { "new1", "new2" }); // Collection now contains only "new1" and "new2"

Advanced Usage

Null Item Handling

using ktsu.Extensions;

var items = new[] { "one", null, "three" };

// Convert to strings with null handling
var strings1 = items.ToStringEnumerable(NullItemHandling.Remove);   // ["one", "three"]
var strings2 = items.ToStringEnumerable(NullItemHandling.Include);  // ["one", null, "three"]
// NullItemHandling.Throw will throw an exception if null items are found

// Join with null handling
var joined = items.Join(", ", NullItemHandling.Remove);  // "one, three"

Reflection Helpers

using ktsu.Extensions;
using System.Reflection;

// Find a method across inheritance hierarchy
if (someType.TryFindMethod("MethodName", BindingFlags.Instance | BindingFlags.Public, out var methodInfo))
{
    // Use the method info
    methodInfo.Invoke(instance, parameters);
}

API Reference

Enumerable Extensions

Method Description
WithIndex Enumerates with the index of each item
ToCollection Converts an enumerable to a collection
ForEach Applies an action to each element
AnyNull Checks if enumerable contains any null items
Join Concatenates elements with a separator
ToStringEnumerable Converts items to strings with null handling
WriteItemsToConsole Displays enumerable items in console

String Extensions

Method Description
StartsWithOrdinal Checks if string starts with value using ordinal comparison
EndsWithOrdinal Checks if string ends with value using ordinal comparison
ContainsOrdinal Checks if string contains value using ordinal comparison
RemovePrefix Removes a prefix from a string if present
RemoveSuffix Removes a suffix from a string if present
ReplaceOrdinal Replaces text using ordinal comparison
DetermineLineEndings Identifies line ending style in a string
NormalizeLineEndings Converts line endings to a specific style
NominalWordWrap Best-effort word wrap on word and hyphen boundaries for a wrap width and nominal glyph width

Collection Extensions

Method Description
AddFrom Adds items from an enumerable to a collection
ReplaceWith Replaces all items in a collection with new items

Dictionary Extensions

Method Description
GetOrCreate Gets existing value or creates new one
AddOrReplace Adds a new value or replaces existing one

Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please make sure to update tests as appropriate.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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. 
.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.
  • .NETStandard 2.0

  • .NETStandard 2.1

    • No dependencies.
  • net10.0

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (14)

Showing the top 5 NuGet packages that depend on ktsu.Extensions:

Package Downloads
ktsu.StrongPaths

A library that provides strong typing for common filesystem paths providing compile time feedback and runtime validation.

ktsu.ImGuiStyler

A library for expressively styling ImGui.NET interfaces.

ktsu.ToStringJsonConverter

A JSON converter for System.Text.Json that handles ToString and Parse methods for value types.

ktsu.TextFilter

A library providing methods for matching and filtering text. It supports glob patterns, regular expressions, and fuzzy matching.

ktsu.ImGuiWidgets

A library of custom widgets using ImGui.NET and utilities to enhance ImGui-based applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.6.4 0 8/19/2026
1.6.3 58 8/19/2026
1.6.2 200 8/18/2026
1.6.1 310 8/17/2026
1.6.0 793 8/12/2026
1.5.36 608 8/11/2026
1.5.35 469 8/7/2026
1.5.34 163 8/6/2026
1.5.33 149 8/6/2026
1.5.32 466 8/5/2026
1.5.31 1,196 7/28/2026
1.5.30 1,094 7/21/2026
1.5.29 807 7/15/2026
1.5.28 364 7/14/2026
1.5.27 613 7/13/2026
1.5.26 882 7/8/2026
1.5.25 947 7/1/2026
1.5.24 469 6/30/2026
1.5.23 447 6/29/2026
1.5.22 529 6/28/2026
Loading failed

## v1.6.4 (patch)

Changes since v1.6.3:

- Bump the ktsu group with 9 updates ([@dependabot[bot]](https://github.com/dependabot[bot]))