When.Core
1.0.0
dotnet add package When.Core --version 1.0.0
NuGet\Install-Package When.Core -Version 1.0.0
<PackageReference Include="When.Core" Version="1.0.0" />
<PackageVersion Include="When.Core" Version="1.0.0" />
<PackageReference Include="When.Core" />
paket add When.Core --version 1.0.0
#r "nuget: When.Core, 1.0.0"
#addin nuget:?package=When.Core&version=1.0.0
#tool nuget:?package=When.Core&version=1.0.0
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
andValueTask
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 | 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 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. |
-
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 |