
Security News
npm ‘is’ Package Hijacked in Expanding Supply Chain Attack
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Use the AnyOf<TFirst, TSecond, ...> type to handle multiple defined types as input parameters for methods.
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>
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;
}
}
}
}
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.
FAQs
Use the AnyOf<TFirst, TSecond, ...> type to handle multiple defined types as input parameters for methods.
We found that anyof demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Security News
A critical flaw in the popular npm form-data package could allow HTTP parameter pollution, affecting millions of projects until patched versions are adopted.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.