Skip to content

Commit 88c8da8

Browse files
committed
1 parent c76714f commit 88c8da8

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,14 @@ private Dictionary<string, object> _properties
187187

188188
foreach (PropertyInfo pi in GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
189189
{
190-
int parameters = pi.GetGetMethod().GetParameters().Length;
191-
if (parameters == 0)
192-
_propertiesDictionary.Add(pi.Name, pi.GetValue(this, null));
190+
int parameters = pi.GetIndexParameters().Length;
191+
if (parameters > 0)
192+
{
193+
// The property is an indexer, skip this.
194+
continue;
195+
}
196+
197+
_propertiesDictionary.Add(pi.Name, pi.GetValue(this, null));
193198
}
194199
}
195200

test/System.Linq.Dynamic.Core.Tests/QueryableTests.GroupBy.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using System.Collections.Generic;
1+
using NFluent;
2+
using System.Collections.Generic;
23
using System.Linq.Dynamic.Core.Exceptions;
34
using System.Linq.Dynamic.Core.Tests.Helpers.Models;
5+
using System.Reflection;
46
using Xunit;
57

68
namespace System.Linq.Dynamic.Core.Tests
@@ -23,6 +25,22 @@ public void GroupBy_Dynamic()
2325
Assert.Equal(testList.GroupBy(x => x.Profile.Age).Count(), byAgeReturnAll.Count());
2426
}
2527

28+
// https://github.com/StefH/System.Linq.Dynamic.Core/issues/75
29+
[Fact]
30+
public void GroupBy_Dynamic_Issue75()
31+
{
32+
var testList = User.GenerateSampleModels(100);
33+
34+
var resultDynamic = testList.AsQueryable().GroupBy("Profile.Age").Select("new (it.key as PropertyKey)");
35+
var result = testList.GroupBy(e => e.Profile.Age).Select(e => new { PropertyKey = e.Key }).AsQueryable();
36+
37+
// I think this should be true, but it isn't. dynamicResult add System.Object Item [System.String] property.
38+
PropertyInfo[] properties = result.ElementType.GetTypeInfo().GetProperties();
39+
PropertyInfo[] propertiesDynamic = resultDynamic.ElementType.GetTypeInfo().GetProperties();
40+
41+
Check.That(propertiesDynamic.Length).IsStrictlyGreaterThan(properties.Length);
42+
}
43+
2644
[Fact]
2745
public void GroupByMany_Dynamic_LambdaExpressions()
2846
{

test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<PackageReference Include="System.Threading.Tasks">
5959
<Version>4.3.0</Version>
6060
</PackageReference>
61+
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.3.0"/>
6162
</ItemGroup>
6263

6364
<ItemGroup>

0 commit comments

Comments
 (0)