Toodle.CommonExtensions 1.0.2

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

Toodle.CommonExtensions

NuGet Version NuGet Downloads A collection of useful extension methods for caching, enum handling, geographic calculations, JSON serialization, and string manipulation.

Installation

Install the package via NuGet:

dotnet add package Toodle.CommonExtensions

Features

Cache Extensions

The CacheExtensions class provides methods for generating cache keys:

Fast Cache Keys
using Toodle.CommonExtensions.Cache;

var person = new Person { Id = 1, Name = "John" };
string key = person.ToCacheKeyFast(); // Returns "Person_[hash]"
string keyWithPrefix = person.ToCacheKeyFast("App1"); // Returns "App1_Person_[hash]"

Note: Hash codes from ToCacheKeyFast are not guaranteed to be consistent across application restarts.

Stable Cache Keys
using Toodle.CommonExtensions.Cache;

var person = new Person { Id = 1, Name = "John" };
string key = person.ToCacheKeyStable(); // Returns "Person_[hash]"
string keyWithPrefix = person.ToCacheKeyStable("App1"); // Returns "App1_Person_[hash]"

Uses FNV-1a hash algorithm to ensure consistency across application restarts.

Enum Extensions

The EnumExtensions class provides methods for working with enums:

using Toodle.CommonExtensions;

public enum Status { Active, Inactive, Pending }

// Get all enum values sorted alphabetically
var allStatuses = EnumExtensions.GetEnumValues<Status>();

// Get enum values excluding specific items
var filteredStatuses = EnumExtensions.GetEnumValues<Status>(
    new[] { Status.Inactive }
);

Geography Helper

The GeographyHelper class provides methods for geographic calculations:

using Toodle.CommonExtensions.Helpers;

// Calculate distance between London and Paris
double distance = GeographyHelper.GetDistance(
    51.5074, -0.1278,  // London coordinates
    48.8566, 2.3522    // Paris coordinates
);
// Returns distance in meters using the Haversine formula

JSON Extensions

The JsonExtensions class provides methods for JSON serialization:

using Toodle.CommonExtensions.Json;

var person = new Person { Name = "John", Age = 30 };

// Basic serialization
string json = person.ToJson();

// Serialization with custom options
var options = new JsonSerializerOptions
{
    WriteIndented = true
};
string prettyJson = person.ToJson(options);

String Extensions

The StringExtensions class provides string manipulation methods:

Converting to Initials
using Toodle.CommonExtensions.String;

string initials = "hello world".ToInitials(); // Returns "HW"
string multipleWords = "United States of America".ToInitials(); // Returns "USOA"
string multipleSpaces = "  multiple   spaces   ".ToInitials(); // Returns "MS"
Removing Non-Alphabetic Characters
using Toodle.CommonExtensions.String;

string cleaned = "Hello123World!".RemoveNonAlphabeticCharacters(); // Returns "HelloWorld"
string numbersOnly = "12345".RemoveNonAlphabeticCharacters(); // Returns ""
string withSpaces = "Hello World!".RemoveNonAlphabeticCharacters(); // Returns "HelloWorld"
Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

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.0.2 100 2/25/2025
1.0.0 99 2/21/2025

Adding:
- String.ToTitleCase()
- String.MonthNameToNumber()
- String.IsCurrentMonth()
- DateTime.Format()