Skip to content

Commit 96fea32

Browse files
committed
* Add unit test and fix public methods access.
1 parent 10fc9a2 commit 96fea32

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/System.Linq.Dynamic.Core/ExpressionParser.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ Expression ParseMemberAccess(Type type, Expression instance)
12671267
throw ParseError(errorPos, Res.NoApplicableMethod, id, GetTypeName(type));
12681268
case 1:
12691269
MethodInfo method = (MethodInfo)mb;
1270-
if (!IsPredefinedType(method.DeclaringType))
1270+
if (!IsPredefinedType(method.DeclaringType) && !(method.IsPublic && IsPredefinedType(method.ReturnType)))
12711271
throw ParseError(errorPos, Res.MethodsAreInaccessible, GetTypeName(method.DeclaringType));
12721272

12731273
if (method.ReturnType == typeof(void))

test/System.Linq.Dynamic.Core.Tests/ExpressionTests.cs

+11
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ public void ExpressionTests_SkipAndTake()
5959
}
6060
}
6161

62+
[Fact]
63+
public void ExpressionTests_Method()
64+
{
65+
var samples1 = User.GenerateSampleModels(3).AsQueryable();
66+
var samples2 = User.GenerateSampleModels(3).ToArray();
67+
68+
var result = samples1.Where("TestMethod(@0)", samples2);
69+
70+
Assert.Equal(samples1.Count(), result.Count());
71+
}
72+
6273
[Fact]
6374
public void ExpressionTests_StringConcatenation()
6475
{

test/System.Linq.Dynamic.Core.Tests/Helpers/Models/User.cs

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ public class User
1616

1717
public List<Role> Roles { get; set; }
1818

19+
public bool TestMethod(User other)
20+
{
21+
return true;
22+
}
23+
1924
public static IList<User> GenerateSampleModels(int total, bool allowNullableProfiles = false)
2025
{
2126
var list = new List<User>();

0 commit comments

Comments
 (0)