Skip to content

Instantly share code, notes, and snippets.

@acple
Last active May 23, 2019 12:12
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 acple/394b5be3609f80cfa03d9d95f7f087c2 to your computer and use it in GitHub Desktop.
Save acple/394b5be3609f80cfa03d9d95f7f087c2 to your computer and use it in GitHub Desktop.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>8.0</LangVersion>
<!-- for Visual Studio 16.2.x Preview -->
<Nullable>enable</Nullable>
<!-- for Visual Studio 2019, .NET Core SDK 3.0 Preview -->
<NullableContextOptions>enable</NullableContextOptions>
</PropertyGroup>
</Project>
using System;
using System.Linq;
namespace ConsoleApp1
{
class Program
{
static bool X(Func<int, bool> predicate) => predicate(default);
static void Main(string[] args)
{
X("abc".GenericExtensionMethod); // CS8622
X(new Program().GenericExtensionMethod); // CS8622
X(new object().GenericExtensionMethod); // No error
X(Enumerable.Empty<int>().GenericExtensionMethod); // CS8622
X(Enumerable.Empty<int>().Contains); // CS8622
}
}
public static class Extension
{
public static bool GenericExtensionMethod<T>(this T instance, int value) => true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment