Chasm.Utilities 2.3.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package Chasm.Utilities --version 2.3.5                
NuGet\Install-Package Chasm.Utilities -Version 2.3.5                
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="Chasm.Utilities" Version="2.3.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Chasm.Utilities --version 2.3.5                
#r "nuget: Chasm.Utilities, 2.3.5"                
#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 Chasm.Utilities as a Cake Addin
#addin nuget:?package=Chasm.Utilities&version=2.3.5

// Install Chasm.Utilities as a Cake Tool
#tool nuget:?package=Chasm.Utilities&version=2.3.5                

Chasm.Utilities

Provides various utility types and methods.

Util

Contains various utility methods, that can be used to shorten common branch code. (or... you could also just not use the auto-formatting, and write everything in a single line, but that's not my style)

Util.Fail sets all out parameters to default and returns either false or a specified return value. Especially useful for parsing.

// Commonly written as:
if (stringIsInvalid) { result = null; return ErrorCode.InvalidString; }

// Using Util.Fail:
if (stringIsInvalid) return Util.Fail(ErrorCode.InvalidString, out result);

Util.Catch catches an exception thrown by the specified delegate. If the delegate returned a value, it can be read through an out parameter.

// Commonly written as:
object? result; Exception? ex;
try { result = doSomething(); ex = null; }
catch (Exception caught) { result = null; ex = caught; }

// Using Util.Catch:
var ex = Util.Catch(doSomething, out object? result);

Util.Is can be used to assign a type-casted value to an existing variable.

// Commonly written as:
if (a is string textA) { /* ... */ }
else if (b is string textB) { /* ... */ }
else if (c is string textC) { /* ... */ }

// Using Util.Is:
if (a is string text) { /* ... */ }
else if (Util.Is(b, out text)) { /* ... */ }
else if (Util.Is(c, out text)) { /* ... */ }

Util.With can be used to invoke functions while using a IDisposable:

// Commonly written as:
string? firstLine;
using (StreamReader reader = File.OpenText(path))
    firstLine = reader.ReadLine();

// Using Util.With:
string? firstLine = With(File.OpenText(path), reader => reader.ReadLine());

Util.Swap just swaps two values. Useful when the tuple swap is too long or prone to errors.

// Commonly written as:
(firstVariable, secondVariable) = (secondVariable, firstVariable);

// Using Util.Swap:
Util.Swap(ref firstVariable, ref secondVariable);

DelegateDisposable

DelegateDisposable is a IDisposable interface implementation that invokes an action on disposal.

store.Subscribe(listenerFunc);
var listener = new DelegateDisposable(() => store.Unsubscribe(listenerFunc));

// Or like this, functional programming style:
var listener = DelegateDisposable.Create(
    () => store.Subscribe(listenerFunc),
    () => store.Unsubscribe(listenerFunc)
);

ReaderWriterLockSlimExtensions makes use of this class.

ReaderWriterLockSlim rwl = new();

// Commonly written as:
try
{
    rwl.EnterReadLock();
    /* ... */
}
finally
{
    rwl.ExitReadLock();
}

// Using ReaderWriterLockSlimExtensions:
using (rwl.WithReaderLock())
    /* ... */
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp1.0 is compatible.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 is compatible.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.0 is compatible.  netstandard1.1 was computed.  netstandard1.2 was computed.  netstandard1.3 was computed.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 was computed.  netstandard2.1 is compatible. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  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 tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Windows Phone wp8 was computed.  wp81 was computed.  wpa81 was computed. 
Windows Store netcore was computed.  netcore45 was computed.  netcore451 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.
  • .NETCoreApp 1.0

  • .NETCoreApp 3.0

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 1.0

  • .NETStandard 2.1

    • No dependencies.
  • net8.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
2.5.2 103 9/28/2024
2.5.1 122 9/6/2024
2.5.0 103 9/6/2024
2.4.0 105 9/5/2024
2.3.7 73 7/30/2024
2.3.6 99 6/11/2024
2.3.5 104 6/7/2024
2.3.4 113 5/9/2024
2.3.3 309 1/2/2024
2.3.2 176 1/1/2024
2.3.1 145 12/30/2023
2.3.0 125 12/29/2023
2.2.0 128 12/17/2023
2.1.0 126 12/16/2023
2.0.0 132 12/16/2023