KutCode.Optionality 0.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package KutCode.Optionality --version 0.0.4
                    
NuGet\Install-Package KutCode.Optionality -Version 0.0.4
                    
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="KutCode.Optionality" Version="0.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KutCode.Optionality" Version="0.0.4" />
                    
Directory.Packages.props
<PackageReference Include="KutCode.Optionality" />
                    
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 KutCode.Optionality --version 0.0.4
                    
#r "nuget: KutCode.Optionality, 0.0.4"
                    
#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=KutCode.Optionality&version=0.0.4
                    
Install as a Cake Addin
#tool nuget:?package=KutCode.Optionality&version=0.0.4
                    
Install as a Cake Tool

.NET library that allows you to easily handle null values in C#.

⚙️ Features

  • Handle nullable value and reference types
  • Easy "from value" creation or static .None stub
  • Built-in Json support System.Text.Json as Serialization and Deserialization

📜 Install

KutCode.Optionality is designed to work with net7.0 and higher.

Install KutCode.Optionality using NuGet Package Manager:

Install-Package KutCode.Optionality

Or via the .NET CLI:

dotnet add package KutCode.Optionality

All versions can be found here.

⌨️ Basic usage

  • Wrap all types for easy nullabillity checks
public Optional<Person> GetPerson()
{
    Person? person = _context.GetPerson();
    return Optional.From<Person>(person);
}

public static void Main()
{
    var person = GetPerson();
    if (person.HasValue) Console.WriteLine(person.Name);
    else Console.WriteLine("Person is not presented");
}
  • Stop use null return - prevent NullReferenceException
public Optional<Person> GetAnyPerson()
{
    try {
        // anything wrong...
    }
    catch {
        return Optional<Person>.None; // .HasValue will return false
    }
}
  • Cast Optional type to TValue implicitly if you need
public void Main()
{
    Optional<Person> person = Optional.From(new Person());
    HandlePerson(person); // implicit casting
}

public void HandlePerson(Person person)
{
    // some actions
}

📦 JSON

KutCode.Optionality allows you to use Optional<T> in JSON-models.

ℹ️ Additional info

🗨️ Telegram

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 was computed.  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 was computed.  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.
  • net7.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.1 654 4/2/2025
1.0.0 162 4/1/2025
0.0.4 732 10/25/2023