You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

AnyOf

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

AnyOf

Use the AnyOf<TFirst, TSecond, ...> type to handle multiple defined types as input parameters for methods.

0.5.0.1
Source
nugetNuGet
Version published
Maintainers
1
Created
Source

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.

Entity Framework Extensions

Dapper Plus

Keywords

AnyOf

FAQs

Package last updated on 13 Jun 2025

Did you know?

Socket

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.

Install

Related posts