Skip to content

Commit 8fd0558

Browse files
committed
uses the topmost implementation of the virtual method
1 parent eaee215 commit 8fd0558

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/System.Linq.Dynamic.Core/Parser/SupportedMethods/MethodFinder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public int FindBestMethodBasedOnArguments(IEnumerable<MethodBase> methods, ref E
105105
if (applicable.Length == 1)
106106
{
107107
MethodData md = applicable[0];
108-
method = md.MethodBase;
108+
method = ((MethodInfo)md.MethodBase).GetBaseDefinition();
109109
args = md.Args;
110110
}
111111
else
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Linq.Expressions;
7+
using static System.Console;
8+
using static System.Linq.Expressions.Expression;
9+
using System.Linq.Dynamic.Core.Parser;
10+
using System.Linq.Dynamic.Core;
11+
using Xunit;
12+
13+
namespace System.Linq.Dynamic.Core.Tests.Parser
14+
{
15+
public class MethodFinderTest
16+
{
17+
[Fact]
18+
public void MethodsOfDynamicLinqAndSystemLinqShouldBeEqual()
19+
{
20+
Expression<Func<int?, string?>> expr = x => x.ToString();
21+
22+
var selector = "ToString()";
23+
var prm = Parameter(typeof(int?));
24+
var parser = new ExpressionParser(new[] { prm }, selector, new object[] { }, ParsingConfig.Default);
25+
var expr1 = parser.Parse(null);
26+
27+
Assert.Equal(((MethodCallExpression)expr.Body).Method.DeclaringType, ((MethodCallExpression)expr1).Method.DeclaringType);
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)