Skip to content

Instantly share code, notes, and snippets.

@Porges
Last active June 27, 2019 05:53
Show Gist options
  • Save Porges/9982e00df3629592409a42f34bf147b1 to your computer and use it in GitHub Desktop.
Save Porges/9982e00df3629592409a42f34bf147b1 to your computer and use it in GitHub Desktop.
absolutely disgusting
interface IHas<out T>
{
T Get { get; }
}
class Base<T> : IHas<T>
{
public Base(T value) => Get = value;
public T Get { get; }
}
class Of<T, U> : Base<T>, IHas<U>
{
public Of(T valT, U valU) : base(valT) => Get = valU;
public new U Get { get; }
}
static class Set
{
public static Of<T, U> Of<T, U>(T t, U u) => new Of<T, U>(t, u);
}
static class Gets
{
public static T Get<T>(this IHas<T> has) => has.Get;
public static T Get<T>(this IHas<IHas<T>> has) => has.Get.Get();
public static T Get<T>(this IHas<IHas<IHas<T>>> has) => has.Get.Get();
public static T Get<T>(this IHas<IHas<IHas<IHas<T>>>> has) => has.Get.Get();
public static T Get<T>(this IHas<IHas<IHas<IHas<IHas<T>>>>> has) => has.Get.Get();
public static T Get<T>(this IHas<IHas<IHas<IHas<IHas<IHas<T>>>>>> has) => has.Get.Get();
public static T Get<T>(this IHas<IHas<IHas<IHas<IHas<IHas<IHas<T>>>>>>> has) => has.Get.Get();
public static T Get<T>(this IHas<IHas<IHas<IHas<IHas<IHas<IHas<IHas<T>>>>>>>> has) => has.Get.Get();
// supports up to 512 types!
public static T Get<T>(this IHas<IHas<IHas<IHas<IHas<IHas<IHas<IHas<IHas<T>>>>>>>>> has) => has.Get.Get();
}
class Program
{
static void Main()
{
var set = Set.Of(Set.Of(1, "str"), Set.Of(2.0, 'c'));
System.Console.WriteLine(set.Get<string>());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment