DotNetExtras.Extended
1.0.1
dotnet add package DotNetExtras.Extended --version 1.0.1
NuGet\Install-Package DotNetExtras.Extended -Version 1.0.1
<PackageReference Include="DotNetExtras.Extended" Version="1.0.1" />
<PackageVersion Include="DotNetExtras.Extended" Version="1.0.1" />
<PackageReference Include="DotNetExtras.Extended" />
paket add DotNetExtras.Extended --version 1.0.1
#r "nuget: DotNetExtras.Extended, 1.0.1"
#:package DotNetExtras.Extended@1.0.1
#addin nuget:?package=DotNetExtras.Extended&version=1.0.1
#tool nuget:?package=DotNetExtras.Extended&version=1.0.1
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 | Versions 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. |
-
net8.0
- DeepCloner (>= 0.10.4)
- DotNetExtras.Common (>= 1.0.5)
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.
Allow the RemoveMatching method to remove elements with matching non-public properties.