Skip to content

Instantly share code, notes, and snippets.

@lawrence-laz
Created July 30, 2020 05:00
Show Gist options
  • Save lawrence-laz/fc7f3739614da5539ea063608d5d1c38 to your computer and use it in GitHub Desktop.
Save lawrence-laz/fc7f3739614da5539ea063608d5d1c38 to your computer and use it in GitHub Desktop.
Weakpoint of generic overload resolution in C#
class Foo
{
public static void Bar<TZoom>(TZoom zoom) where TZoom : IZoom { }
public static void Bar<TBoom, TLoom>(TBoom boom) where TBoom : IBoom<TLoom> { }
}
interface IZoom { }
interface IBoom<T> { }
class Zoom1 : IZoom { }
class Zoom2 : IZoom { }
class Boom1 : IBoom<Loom> { }
class Boom2 : IBoom<Loom> { }
class Loom { }
var boom = new Boom1();
Foo.Bar(boom); // Error, cannot convert Boom1 to IZoom.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment