Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<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
You can’t perform that action at this time.