KutCode.Optionality
0.0.4
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.
paket add KutCode.Optionality --version 0.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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.
// Install KutCode.Optionality as a Cake Addin #addin nuget:?package=KutCode.Optionality&version=0.0.4 // Install KutCode.Optionality as a Cake Tool #tool nuget:?package=KutCode.Optionality&version=0.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
.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 | Versions 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. |
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 |
---|---|---|
0.0.4 | 501 | 10/25/2023 |