AnyOf.SourceGenerator
0.5.0.1
Prefix Reserved
dotnet add package AnyOf.SourceGenerator --version 0.5.0.1
NuGet\Install-Package AnyOf.SourceGenerator -Version 0.5.0.1
<PackageReference Include="AnyOf.SourceGenerator" Version="0.5.0.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="AnyOf.SourceGenerator" Version="0.5.0.1" />
<PackageReference Include="AnyOf.SourceGenerator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add AnyOf.SourceGenerator --version 0.5.0.1
#r "nuget: AnyOf.SourceGenerator, 0.5.0.1"
#addin nuget:?package=AnyOf.SourceGenerator&version=0.5.0.1
#tool nuget:?package=AnyOf.SourceGenerator&version=0.5.0.1
AnyOf
Use the AnyOf<First, TSecond, ...>
type to handle multiple defined types as input parameters for methods.
This project uses code generation to generate up to 10 AnyOf-types:
AnyOf<TFirst, TSecond>
AnyOf<TFirst, TSecond, TThird>
AnyOf<TFirst, TSecond, TThird, TFourth>
- ...
Usage
using System;
using AnyOfTypes;
namespace ConsoleAppConsumer
{
internal class Program
{
private static void Main(string[] args)
{
Console.WriteLine(ReturnSomething().CurrentValue);
X(42);
X("test");
}
// This method returns an string, int or bool in a random way.
private static AnyOf<string, int, bool> ReturnSomething()
{
return new Random().Next(3) switch
{
1 => "test",
2 => 42,
_ => true,
};
}
// This method accepts only an int and a string.
private static void X(AnyOf<int, string> value)
{
Console.WriteLine("ToString " + value.ToString());
Console.WriteLine("CurrentValue " + value.CurrentValue);
Console.WriteLine("IsUndefined " + value.IsUndefined);
Console.WriteLine("IsFirst " + value.IsFirst);
Console.WriteLine("IsSecond " + value.IsSecond);
switch (value.CurrentType)
{
case AnyOfType.First:
Console.WriteLine("AnyOfType = First with value " + value.First);
break;
case AnyOfType.Second:
Console.WriteLine("AnyOfType = Second with value " + value.Second);
break;
default:
Console.WriteLine("???");
break;
}
}
}
}
Sponsors
Entity Framework Extensions and Dapper Plus are major sponsors and proud to contribute to the development of AnyOf, AnyOf.Newtonsoft.Json and AnyOf.System.Text.Json.
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 was computed. 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 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. 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.0
- Microsoft.Bcl.HashCode (>= 1.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
# 0.5.0 (24 November 2024)
- #23 Fix AnyOfJsonConverter (string and string list) [bug]
- #22 Null pointer in AnyOfJsonConverter.cs [bug]
The full release notes can be found here: https://github.com/StefH/AnyOf/blob/main/ReleaseNotes.md