Soenneker.Atomics.ValueNullableLazys 4.0.12

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

Soenneker.Atomics.ValueNullableLazys

Provides inline lazy storage that distinguishes an uninitialized value from a successfully initialized null result.

Install

dotnet add package Soenneker.Atomics.ValueNullableLazys

Usage

Use this variant when null is a valid, cacheable factory result:

using Soenneker.Atomics.ValueLocks;
using Soenneker.Atomics.ValueNullableLazys;

public sealed class UserLookup
{
    private ValueAtomicLock _sync;
    private ValueNullableLazy<User> _user;

    public User? Get(string id) => _user.GetOrCreate(
        ref _sync,
        id,
        static userId => FindUser(userId));
}

After the factory returns—even when it returns nullIsValueCreated is true and later calls reuse that result. TryGetValue distinguishes the states: a false return means uninitialized; a true return with a null output means initialized-to-null.

GetOrCreate runs one factory under the supplied lock and retries after exceptions. GetOrCreatePublicationOnly may run duplicate factories during a race, while GetOrCreateUnsafe requires external synchronization.

Keep both mutable structs in fields. Copies have independent lazy state or lock domains. Publication-only factories should be side-effect free, and losing non-null candidates are not disposed automatically.

What you get

  • ValueNullableLazy<T> — Provides inline lazy storage that distinguishes an uninitialized value from a successfully initialized null result.

API at a glance

API What it does Result / important behavior
ValueNullableLazy<T>.IsValueCreated Gets a value indicating whether initialization has completed successfully, including when the result was null. Gets a value indicating whether initialization has completed successfully, including when the result was null.
ValueNullableLazy<T>.TryGetValue(value) Attempts to read the initialized value without invoking a factory. A true return value with a null output means initialization completed with null. true if the requested update was applied; otherwise, false.
ValueNullableLazy<T>.GetOrCreate(sync, factory) Gets the initialized value or invokes factory exactly once using execution-and-publication semantics. The requested value.
ValueNullableLazy<T>.GetOrCreate(sync, state, factory) Gets the initialized value or invokes factory exactly once using execution-and-publication semantics. Supplying state allows callers to use a static factory and avoid a closure allocation. The requested value.
ValueNullableLazy<T>.GetOrCreateUnsafe(factory) Gets or creates the value without locking. This method is only safe when the caller provides external synchronization or guarantees single-threaded access. The requested value.
ValueNullableLazy<T>.GetOrCreateUnsafe(state, factory) Gets or creates the value without locking. Supplying state allows callers to use a static factory and avoid a closure allocation. The requested value.
ValueNullableLazy<T>.GetOrCreatePublicationOnly(factory) Gets the initialized value or atomically publishes one factory result. During a race the factory may run more than once, but every caller observes the single published result. The requested value.
ValueNullableLazy<T>.GetOrCreatePublicationOnly(state, factory) Gets the initialized value or atomically publishes one factory result. Supplying state allows callers to use a static factory and avoid a closure allocation. The requested value.

Important behavior

  • ValueNullableLazy<T>: The default value is ready to use and occupies one reference-sized field. A ValueAtomicLock can be shared by several lazy fields on the same owner, avoiding a separate synchronization object for every value. This is a mutable struct intended for use as a private field. Avoid copying it because each copy has independent initialization state. Exceptions thrown by a factory are not cached, and a later call may retry initialization.
Product Compatible and additional computed target framework versions.
.NET 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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Soenneker.Atomics.ValueNullableLazys:

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.12 62 9/2/2026
4.0.11 31 9/1/2026
4.0.10 31 9/1/2026
4.0.9 35 9/1/2026
4.0.8 3,007 9/1/2026
4.0.7 391 9/1/2026
4.0.6 6,187 8/31/2026
4.0.5 12,504 8/29/2026
4.0.4 81 8/29/2026
4.0.3 74 8/29/2026
4.0.2 48,770 8/27/2026
4.0.1 163 8/26/2026