CSharpEssentials.Any
6.2.0
See the version list below for details.
dotnet add package CSharpEssentials.Any --version 6.2.0
NuGet\Install-Package CSharpEssentials.Any -Version 6.2.0
<PackageReference Include="CSharpEssentials.Any" Version="6.2.0" />
<PackageVersion Include="CSharpEssentials.Any" Version="6.2.0" />
<PackageReference Include="CSharpEssentials.Any" />
paket add CSharpEssentials.Any --version 6.2.0
#r "nuget: CSharpEssentials.Any, 6.2.0"
#:package CSharpEssentials.Any@6.2.0
#addin nuget:?package=CSharpEssentials.Any&version=6.2.0
#tool nuget:?package=CSharpEssentials.Any&version=6.2.0
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 to 8 types:
Any<T0, T1>throughAny<T0, ..., T7>. - Implicit Conversions: Assign values directly to the union type.
- Pattern Matching:
SwitchandMatchfor exhaustive handling. - Type Helpers:
Is<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");
// Match returns AnyActionResult<TResult>: Status tells whether a handler ran, Result holds its value
AnyActionResult<string> output = result.Match(
first: str => $"String: {str}",
second: num => $"Number: {num}");
Console.WriteLine(output.Result);
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}"));
Collection Extensions
Scatter a sequence of unions into typed arrays in one pass:
// Classify API responses into successes and errors
var (users, errors) = responses
.Traverse(r => ClassifyResponse(r)); // returns Any<UserDto, ApiError>
// Or partition an existing sequence of unions
var (drafts, published) = articles
.Select(a => GetState(a)) // returns Any<Draft, Published>
.Partition();
Partition and Traverse are available for all arities (Any<T0,T1> through Any<T0,...,T7>), returning a tuple with one typed array per variant.
| Product | Versions 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. |
-
.NETStandard 2.1
- CSharpEssentials.Core (>= 6.2.0)
- CSharpEssentials.Json (>= 6.2.0)
- System.Text.Json (>= 9.0.4)
-
net10.0
- CSharpEssentials.Core (>= 6.2.0)
- CSharpEssentials.Json (>= 6.2.0)
-
net11.0
- CSharpEssentials.Core (>= 6.2.0)
- CSharpEssentials.Json (>= 6.2.0)
-
net9.0
- CSharpEssentials.Core (>= 6.2.0)
- CSharpEssentials.Json (>= 6.2.0)
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 |
|---|---|---|
| 6.5.2 | 111 | 10/10/2026 |
| 6.5.1 | 108 | 10/10/2026 |
| 6.5.0 | 107 | 10/9/2026 |
| 6.4.0 | 111 | 10/9/2026 |
| 6.3.0 | 118 | 10/8/2026 |
| 6.2.0 | 110 | 10/8/2026 |
| 6.1.0 | 111 | 10/7/2026 |
| 6.0.0 | 112 | 10/7/2026 |
| 5.2.1 | 111 | 10/7/2026 |
| 5.2.0 | 112 | 10/7/2026 |
| 5.1.0 | 110 | 10/7/2026 |
| 5.0.0 | 109 | 10/6/2026 |
| 4.1.0 | 116 | 10/6/2026 |
| 4.0.0 | 113 | 10/5/2026 |
| 3.2.3 | 286 | 5/31/2026 |
| 3.2.2 | 161 | 5/31/2026 |
| 3.2.1 | 156 | 5/31/2026 |
| 3.2.0 | 156 | 5/30/2026 |
| 3.1.0 | 170 | 5/27/2026 |
| 3.0.8 | 154 | 5/20/2026 |