Pick.Net.Utilities 1.0.0-preview5

This is a prerelease version of Pick.Net.Utilities.
dotnet add package Pick.Net.Utilities --version 1.0.0-preview5
NuGet\Install-Package Pick.Net.Utilities -Version 1.0.0-preview5
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="Pick.Net.Utilities" Version="1.0.0-preview5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pick.Net.Utilities --version 1.0.0-preview5
#r "nuget: Pick.Net.Utilities, 1.0.0-preview5"
#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.
// Install Pick.Net.Utilities as a Cake Addin
#addin nuget:?package=Pick.Net.Utilities&version=1.0.0-preview5&prerelease

// Install Pick.Net.Utilities as a Cake Tool
#tool nuget:?package=Pick.Net.Utilities&version=1.0.0-preview5&prerelease

Pick.Net.Utilites

Various helper classes for C#.

Abstract collection classes

Abstract classes is designed to serve as a base class for creating read-only collections. Methods that modify the collection (i.e. Add, Clear, and Remove) will throw a NotSupportedException.

public class SingleItemCollection(string item) : AbstractReadOnlyCollection<string>
{
	public override int Count => 1;

	public override IEnumerator<string> GetEnumerator()
	{
		yield return item;
	}
}

var collection = new SimpleCollection("test");
var array = collection.ToArray();
// [ "test" ]
((ICollection<T>)collection).Add("another item")
// throws a NotSupportedException

Map

A dictionary-like collection with that allows covariance of the value type parameter and returns null instead of throwing a KeyNotFound exception when accessing a key not in the collection. Only supports reference type values.

var map = new Map<string, string>
{
	{ "key1", "value1" },
	{ "key2", "value2" },
	{ "key3", "value3" }
};

var value1 = map["key1"];
// "value1"
var value4 = map["key4"];
// null

IReadOnlyMap<string, object> objectMap = map;
var value2 = objectMap["key2"];
// "value2"

StringDictionary

A string-keyed dictionary that allows char spans to be used to get values

var map = new StringDictionary<object>
{
	{ "key1", "value1" },
	{ "key2", "value2" },
	{ "key3", "value3" }
};

ReadOnlySpan<char> keys = "key1;key2;key3";

var value1 = map[keys[..4]];
// "value1"
var value2 = map[keys[5..^5]];
// "value2"
var value3 = map[keys[^4..]];
// "value3"

DelegateHelper

Shortcuts for MethodInfo.CreateDelegate for System.Action and System.Func delegates.

Action<object> handler = method.CreateAction<object>();
Func<int, string, bool> handler = method.CreateFunc<int, string, bool>();

Get delegate parameter and return types

ImmutableArray<Type> types = DelegateHelper.GetParameterTypes<Action<string, int>>();
// [ typeof(string), typeof(int) ]
Type types = DelegateHelper.GetReturnType<Func<string>>();
// typeof(string)

Atomic Values

Value type wrappers for int, uint, long, ulong, float and double that use the System.Threading.Interlocked class to perform atomic operations. e.g.

private int value;

void DoSomething()
{
	var next = Interlocked.Increment(ref value);
	var old = Interlocked.Exchange(ref value, 5);
	if (Interlocked.CompareExchange(ref value, 0, 5) == 5)
	{
		...
	}
}

Can be simplified to

private AtomicInt32 value;

void DoSomething()
{
	var next = value.Increment();
	var old = value.Set(5);
	if (value.TrySet(0, 5))
	{
		...
	}
}
Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Pick.Net.Utilities:

Package Downloads
Pick.Net.Utilities.Maui

Code generator for creating .NET MAUI BindableProperty declarations and various helper classes for developing MAUI applications

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0-preview5 84 3/5/2024
1.0.0-preview4 209 12/20/2023
1.0.0-preview1 68 12/6/2023