CSharpEssentials.Any 3.0.4

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

CSharpEssentials.Any

Discriminated Unions (Sum Types) for .NET. A type-safe way to represent a value that can be one of several fixed types.

Features

  • Unions of 2–8 typesAny<T0, T1> through Any<T0, ..., T7>.
  • Implicit Conversions — Assign values directly to the union type.
  • Pattern MatchingSwitch and Match for exhaustive handling.
  • Type HelpersIs<T>, As<T>, TryAs<T>, Deconstruct, ToTuple.
  • JSON Support — Built-in serialization.

Installation

dotnet add package CSharpEssentials.Any

Usage

Creating Unions

using CSharpEssentials.Any;

Any<string, int> ParseInput(string input)
{
    if (int.TryParse(input, out int n))
        return n; // implicit to Any<string, int>
    return input;
}

Pattern Matching

Any<string, int> result = ParseInput("123");

string output = result.Match(
    first: str => $"String: {str}",
    second: num => $"Number: {num}");

result.Switch(
    first: str => Console.WriteLine("It's a string"),
    second: num => Console.WriteLine("It's a number"));

Type Checking

if (result.IsSecond)
{
    int val = result.GetSecond();
}

// Generic helpers
bool isInt = result.Is<int, string, int>();
int? asInt = result.As<int, string, int>();
bool found = result.TryAs<int, string, int>(out int value);

Multiple Types

Any<string, int, Exception> response = GetData(5);

response.Switch(
    first: s => Console.WriteLine($"Success: {s}"),
    second: i => Console.WriteLine($"NotFound: {i}"),
    third: e => Console.WriteLine($"Error: {e.Message}"));
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  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.  net11.0 is compatible. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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 CSharpEssentials.Any:

Package Downloads
CSharpEssentials

A comprehensive C# library enhancing functional programming capabilities with type-safe monads (Maybe, Result), discriminated unions (Any), and robust error handling. Features include: domain-driven design support, enhanced Entity Framework integration, testable time management, JSON utilities, and LINQ extensions. Built for modern C# development with focus on maintainability, testability, and functional programming principles.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.4 0 5/6/2026
3.0.3 3 5/5/2026
3.0.2 79 5/5/2026
3.0.1 87 5/3/2026
3.0.0 89 5/3/2026
2.1.0 271 11/26/2025
2.0.9 233 9/30/2025
2.0.8 228 9/29/2025
2.0.7 215 9/29/2025
2.0.6 213 9/29/2025
2.0.5 224 9/29/2025
2.0.4 206 9/28/2025
2.0.3 218 9/28/2025
2.0.2 227 9/28/2025
2.0.1 226 9/28/2025
2.0.0 223 9/28/2025