Browse Source

Extension method syntax on lambda expressions/delegates is not allowed.

pull/1596/head
Siegfried Pammer 6 years ago
parent
commit
89a50e64fc
  1. 16
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs
  2. 2
      ICSharpCode.Decompiler/CSharp/Transforms/IntroduceExtensionMethods.cs

16
ICSharpCode.Decompiler.Tests/TestCases/Pretty/DelegateConstruction.cs

@ -159,6 +159,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -159,6 +159,17 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
}
public static Predicate<T> And<T>(this Predicate<T> filter1, Predicate<T> filter2)
{
if (filter1 == null) {
return filter2;
}
if (filter2 == null) {
return filter1;
}
return (T m) => filter1(m) && filter2(m);
}
public static Action<string> ExtensionMethodUnbound()
{
return Test;
@ -174,6 +185,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -174,6 +185,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return ((string)null).Test;
}
public static Predicate<int> NoExtensionMethodOnLambda()
{
return And((int x) => x >= 0, (int x) => x <= 100);
}
public static object StaticMethod()
{
return new Func<Action>(ExtensionMethodBound);

2
ICSharpCode.Decompiler/CSharp/Transforms/IntroduceExtensionMethods.cs

@ -162,6 +162,8 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -162,6 +162,8 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
public static bool CanTransformToExtensionMethodCall(CSharpResolver resolver, IMethod method,
IReadOnlyList<IType> typeArguments, ResolveResult target, ResolveResult[] arguments, string[] argumentNames)
{
if (target is LambdaResolveResult)
return false;
var rr = resolver.ResolveMemberAccess(target, method.Name, typeArguments, NameLookupMode.InvocationTarget) as MethodGroupResolveResult;
if (rr == null)
return false;

Loading…
Cancel
Save