AlinSpace.Optionals 1.0.5

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package AlinSpace.Optionals --version 1.0.5
NuGet\Install-Package AlinSpace.Optionals -Version 1.0.5
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="AlinSpace.Optionals" Version="1.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AlinSpace.Optionals --version 1.0.5
#r "nuget: AlinSpace.Optionals, 1.0.5"
#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.
// Install AlinSpace.Optionals as a Cake Addin
#addin nuget:?package=AlinSpace.Optionals&version=1.0.5

// Install AlinSpace.Optionals as a Cake Tool
#tool nuget:?package=AlinSpace.Optionals&version=1.0.5

AlinSpace.Optional

NuGet version (AlinSpace.Optional)

AlinSpace Optional Types.

Why?

In C# reference types can either point to an object (be not "null") or not point to any object (be "null"). Value types can't be "null".

However, both reference and value types can be "default". But "default" does not mean the same for reference and value types. For reference types it means "null" and for value types it means the default value (e.g. for integer it is 0).

Optionals help with this problem, by making both reference and value types behave the same.

Examples

The following optional contains the value 5:

Optional<int> optional = Optional<int>.Some(5);

// Same as above.
Optional<int> optional = 5;

optional.HasValue // true
optional.HasNoValue // false
optional.Value // 5
optional.ValueOrDefault // 5

The following optional contains no value:

Optional<int> optional = Optional<int>.None();

optional.HasValue // false
optional.HasNoValue // true
optional.Value // throws OptionalHasNoValueException
optional.ValueOrDefault // 0

However be careful about "default". The optional will have a value:

Optional<int> optional = default;

optional.HasValue // true
optional.HasNoValue // false
optional.Value // 0
optional.ValueOrDefault // 0
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.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.5 205 11/8/2022