TruthyFalsey 1.0.2

dotnet add package TruthyFalsey --version 1.0.2
                    
NuGet\Install-Package TruthyFalsey -Version 1.0.2
                    
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="TruthyFalsey" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TruthyFalsey" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="TruthyFalsey" />
                    
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 TruthyFalsey --version 1.0.2
                    
#r "nuget: TruthyFalsey, 1.0.2"
                    
#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.
#:package TruthyFalsey@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TruthyFalsey&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=TruthyFalsey&version=1.0.2
                    
Install as a Cake Tool

Want to see what's changed?

Changelog

TruthyFalsey

Slim .Net package giving you Truthy and Falsey evaluation in C# similar to JavaScript.

This project is inspired by Nick Chapsas' video on the topic on Youtube.

Installation

I recommend using the NuGet package: TruthyFalsey however feel free to clone the source instead if that suits your needs better.

Usage

Simply install the package in your project and you're good to go.

You'll now be able to evaluate truthy and falsey values in C# like this:

User? user = await GetUserAsync();
int userAge = user?.Age ?? 0;

if (user)
{
    // User exists
}

if (!user)
{
    // User is null
}

if (userAge)
{
    // User age is different than 0
}

if (!userAge)
{
    // User age is exactly 0
}

The logic behind the above is essentially: "is the value different to what would be the default for the type".

So for any reference types (class, record) it becomes a null check.

For value types (struct, enum, int, etc.) it becomes a comparison to the default value.

The intention here is to mimic how javascript does it.

All of the above is archived by overriding these 3 operators via extension methods:

public static bool operator true
public static bool operator false
public static bool operator !
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.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.2 105 1/30/2026
1.0.1 99 1/30/2026
1.0.0 98 1/30/2026