DotNetExtras.Extended 1.0.1

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

DotNetExtras.Extended

DotNetExtras.Extended is a general-purpose .NET Core library that implements useful extension methods for common data types.

Use the DotNetExtras.Extended library to:

  • Deep clone objects.
  • Remove list elements that match the specified criteria.
  • Check if a string value contains JSON.
  • Check if a string value contains HTML.
  • Convert a string to a different data type, such as <c>DateTime</c>.
  • Convert a tokenized string to an array, dictionary, list, or hash set.

Usage

The following examples illustrates various operations implemented by the DotNetExtras.Extended library.

Convert string values to simple data types

using DotNetExtras.Extended;
...
bool b = "true".ToType<bool>();
int n = "123".ToType<int>();
DateTime dt = "2021-10-11T17:54:38".ToType<DateTime>();
DateTimeOffset dto = "2021-10-11T17:54:38-03:30".ToType<DateTimeOffset>();

Convert string values to arrays, lists, dictionaries, has sets

using DotNetExtras.Extended;
...
// Will hold: value1, value2, value3
string[] result = "value1|value2|value3".ToArray<string>(); 

// Will hold: value1, value2, value3
List<string> list = "value1|value2|value3".ToList<string>();

// Will hold: key1=value1, key2=value2
Dictionary<string,string> result = "key1=value1|key2=value2".ToDictionary<string, string>();

// Will hold: [1, 2, 3]
HashSet<int>? hashSet = "1|2|3".ToHashSet();

// Will hold: ["one", "two", "three"]
HashSet<string>? hashSet = "one,two,three".ToHashSet(",");

Check if string contains a valid JSON or HTML document

using DotNetExtras.Extended;
...
bool isJson;

// This test can handle both a single element and an array.
isJson = "{\"key1\": \"value1\", \"key2\": \"value2\"}".IsJson(); // true
isJson = "[{\"key1\": \"value1\"}, {\"key2\": \"value2\", \"key3\": 123}]".IsJson(); // true

bool isHtml;

// This test only checks if the string starts with the html tag.
isHtml = "<!DOCTYPE html>hello</html>".IsHtml(); // true
isHtml = "<html>hello</html>".IsHtml(); // true

Escape special LDAP characters in a string

using DotNetExtras.Extended;
...
// Will hold:
string escaped = "Hello, world!".EscapeLdapValue();

Deep clone an object

using DotNetExtras.Extended;
...
User clone = original.Clone();

Remove elements from the list

List<Sample> elements = new()
{
    new(){ Id = 100, ParentId = 1, Name = "Item1" },
    new(){ Id = 200, ParentId = 2, Name = "Item2" },
    new(){ Id = 300, ParentId = 2, Name = "Item3" },
    new(){ Id = 400, ParentId = 3, Name = "Item4" }
};

Sample match = new() { ParentId = 2 };

// Removes two items with ParentId = 2.
int removedCount = elements.RemoveMatching(match);

Documentation

For complete documentation, usage details, and code samples, see:

Package

Install the latest version of the DotNetExtras.Extended NuGet package from:

See also

Check out other DotNetExtras libraries at:

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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 was computed.  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 (1)

Showing the top 1 NuGet packages that depend on DotNetExtras.Extended:

Package Downloads
DotNetExtras.Security

A .NET Core library implementing security functions, such as random password generation, encryption, hashing, etc.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 170 8/30/2025
1.0.0 183 8/28/2025

Allow the RemoveMatching method to remove elements with matching non-public properties.