AlinSpace.Optionals
1.0.5
Prefix Reserved
dotnet add package AlinSpace.Optionals --version 1.0.5
NuGet\Install-Package AlinSpace.Optionals -Version 1.0.5
<PackageReference Include="AlinSpace.Optionals" Version="1.0.5" />
paket add AlinSpace.Optionals --version 1.0.5
#r "nuget: AlinSpace.Optionals, 1.0.5"
// 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
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 | Versions 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. |
-
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 | 251 | 11/8/2022 |