Skip to content

Instantly share code, notes, and snippets.

@kyubuns
Last active March 1, 2021 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyubuns/1cf0305538ae582d7d2484d0605534cb to your computer and use it in GitHub Desktop.
Save kyubuns/1cf0305538ae582d7d2484d0605534cb to your computer and use it in GitHub Desktop.
using System;
public sealed class Dummy<T> { private Dummy() {} }
public interface IInterfaceA { }
public interface IInterfaceB { }
public class Hoge : IInterfaceA { }
public class Sandbox
{
public static void Call<T>(T item, Dummy<IInterfaceA> dummy = default) where T : IInterfaceA => Console.WriteLine($"{item} is A");
public static void Call<T>(T item, Dummy<IInterfaceB> dummy = default) where T : IInterfaceB => Console.WriteLine($"{item} is B");
}
Sandbox.Call(new Hoge()); // Hoge is A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment