Soenneker.Utils.LazyBools 4.0.20

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

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image Soenneker.Utils.LazyBools

A tiny, allocation-free, publication-only lazy initializer for bools.

Installation

dotnet add package Soenneker.Utils.LazyBools

Quick start

using Soenneker.Utils.LazyBools;

public sealed class Feature
{
    private int _isAvailableState;

    public bool IsAvailable => LazyBoolUtil.GetOrInit(
        ref _isAvailableState,
        threadSafe: true,
        this,
        static feature => feature.CheckAvailability());

    private bool CheckAvailability() => /* expensive check */ true;
}

Call the static LazyBoolUtil methods directly; no dependency-injection registration is required.

Semantics

GetOrInit stores its state in the caller-provided int: 0 is uninitialized, 1 is false, and 2 is true. Initialize the field to zero and do not use or mutate it for anything else.

With threadSafe: true, initialization is publication-only. Concurrent callers can run compute more than once, but one result is published and returned to every caller. Use a side-effect-free or otherwise concurrency-safe delegate. If the delegate throws before a value is published, the state remains uninitialized and a later call can retry.

Use threadSafe: false only when calls are single-threaded or protected by external synchronization. That path avoids the interlocked publication operation.

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.  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.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Soenneker.Utils.LazyBools:

Package Downloads
Soenneker.Reflection.Cache

The fastest .NET Reflection cache

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.20 16,464 9/15/2026
4.0.19 43,068 9/12/2026
4.0.18 137,386 8/30/2026
4.0.17 6,651 8/29/2026
4.0.16 105 8/29/2026
4.0.15 193,128 7/28/2026
4.0.14 98,581 7/16/2026
4.0.13 132,097 6/19/2026
4.0.12 118,878 6/5/2026
4.0.11 199,861 4/23/2026
4.0.10 119,409 3/14/2026
4.0.5 47,088 3/10/2026
4.0.4 22,731 3/9/2026
4.0.3 230 3/9/2026
4.0.2 49,724 3/4/2026
4.0.1 51,608 2/23/2026

Update dependency dotnet-sdk to v10.0.401 (#51)

Automatically merged