When.Core 1.0.0

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

.NET Coverage Status Nuget download

icon When

Overview

When is a minimalist C# library designed for developers who prefer to avoid the verbosity of traditional if statements, especially when dealing with single-line conditions. By offering extension methods for the bool type, When enables the execution of synchronous and asynchronous actions based on boolean evaluations, resulting in cleaner and more readable code.

Features

  • Synchronous Execution: Execute actions when a boolean value is true, false, or based on either condition.

  • Asynchronous Support: Handle asynchronous tasks with Task and ValueTask return types, facilitating seamless integration with modern async programming patterns.

Example Usage

If you hate how this codes looks

public async Task DoSomething(bool condition)
{
    if (condition)
    {
        await Console.Out.WriteLineAsync("Condition is true.");
    }
    else
    {
        await Console.Out.WriteLineAsync("Condition is false.");
    }
}

// Or even simpler synchronous code like

public void DoSomething(bool condition)
{
    if (condition) Console.WriteLine("Condition is true.");
}

because you really want to write code like

using When.Core.Extensions;

public async Task DoSomething(bool condition)

    => await condition.WhenTrueElse(() => Console.Out.WriteLineAsync("Condition is true."), () =>  Console.Out.WriteLineAsync("Condition is false."))

public void DoSomething(bool condition)

    => condition.WhenTrue(() => Console.WriteLine("Condition is true."));   

Then you might like When.

Its probably one of the most trivial nuget packages that you will ever stumble across, but it keeps me happy so I thought I would share it.

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 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.
  • 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.0 136 13 days ago