Skip to content

Commit cd01952

Browse files
committed
Fixed issue #4
1 parent 7e47c23 commit cd01952

17 files changed

+230
-4
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static AppDomain()
2121
#if (NETSTANDARD)
2222
public Assembly[] GetAssemblies()
2323
{
24-
return new List<Assembly>().ToArray();
24+
return new List<Assembly>().ToArray(); // TODO
2525
}
2626
#elif DNXCORE50
2727
public Assembly[] GetAssemblies()

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

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public T GetDynamicProperty<T>(string propertyName)
1515
return (T)propInfo.GetValue(this, null);
1616
}
1717

18+
public object GetDynamicProperty(string propertyName)
19+
{
20+
return GetDynamicProperty<object>(propertyName);
21+
}
22+
1823
public void SetDynamicProperty<T>(string propertyName, T value)
1924
{
2025
var type = GetType();

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ public static Type CreateType([NotNull] IList<DynamicProperty> properties)
259259
// Equals()
260260
MethodInfo equalityComparerTDefault = TypeBuilder.GetMethod(equalityComparerT, EqualityComparerDefault);
261261
MethodInfo equalityComparerTEquals = TypeBuilder.GetMethod(equalityComparerT, EqualityComparerEquals);
262-
ilgeneratorEquals.Emit(OpCodes.Brfalse_S, equalsLabel);
262+
263+
// Illegal one-byte branch at position: 9. Requested branch was: 143.
264+
// So replace OpCodes.Brfalse_S to OpCodes.Brfalse
265+
ilgeneratorEquals.Emit(OpCodes.Brfalse, equalsLabel);
263266
ilgeneratorEquals.Emit(OpCodes.Call, equalityComparerTDefault);
264267
ilgeneratorEquals.Emit(OpCodes.Ldarg_0);
265268
ilgeneratorEquals.Emit(OpCodes.Ldfld, fields[i]);

src/System.Linq.Dynamic.Core/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"owners": [ "Stef Heyenrath" ],
99
"projectUrl": "https://github.com/StefH/System.Linq.Dynamic.Core",
1010
"licenseUrl": "https://github.com/StefH/System.Linq.Dynamic.Core/blob/master/licence.txt",
11-
"releaseNotes": "",
11+
"releaseNotes": "Fixed issue #1, #2 and #4",
1212

1313
"compilationOptions": {
1414
},

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

+45-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,55 @@
1-
using System.Linq.Dynamic.Core.Tests.Helpers;
1+
using System.Collections.Generic;
22
using System.Linq.Dynamic.Core.Tests.Helpers.Models;
33
using Xunit;
44

55
namespace System.Linq.Dynamic.Core.Tests
66
{
77
public class ComplexTests
88
{
9+
/// <summary>
10+
/// groupByExpressionX "new (new (Company.Name as CompanyName) as GroupByFields)" string
11+
/// </summary>
12+
[Fact]
13+
public void GroupByAndSelect_Test_Illegal_one_byte_branch_at_position_9_Requested_branch_was_143()
14+
{
15+
var testList = new List<Entities.Employee>();
16+
var qry = testList.AsQueryable();
17+
18+
string keySelector = "new (new (Company.Name as CompanyName) as GroupByFields)";
19+
var group = qry.GroupBy(keySelector);
20+
Assert.NotNull(group);
21+
22+
var result = group.ToDynamicList();
23+
Assert.NotNull(result);
24+
}
25+
26+
/// <summary>
27+
/// groupByExpressionX "new (new (Company.Name as CompanyName) as GroupByFields)" string
28+
/// string.Format("new (it AS TEntity__{0})", includesX) "new (it AS TEntity__, it.Company as TEntity__Company, it.Company.MainCompany as TEntity__Company_MainCompany, it.Country as TEntity__Country, it.Function as TEntity__Function, it.SubFunction as TEntity__SubFunction)" string
29+
/// selectExpressionBeforeOrderByX = "new (Key.GroupByFields, it as Grouping , new (Count() as count__CompanyName, Min(TEntity__.EmployeeNumber) as min__Number, Max(TEntity__.EmployeeNumber) as max__Number, Average(TEntity__.EmployeeNumber) as average__Number, Sum(TEntity__.EmployeeNumber) as sum__Number) as Aggregates)";
30+
/// </summary>
31+
[Fact]
32+
public void GroupByAndSelect_Test_GroupByWithSelect()
33+
{
34+
var testList = new List<Entities.Employee>();
35+
var qry = testList.AsQueryable();
36+
37+
string keySelector = "new (new (Company.Name as CompanyName) as GroupByFields)";
38+
string resultSelector = "new (it AS TEntity__, it.Company as TEntity__Company, it.Company.MainCompany as TEntity__Company_MainCompany, it.Country as TEntity__Country, it.Function as TEntity__Function, it.SubFunction as TEntity__SubFunction)";
39+
var group = qry.GroupBy(keySelector, resultSelector);
40+
Assert.NotNull(group);
41+
42+
var result = group.ToDynamicList();
43+
Assert.NotNull(result);
44+
45+
string selectExpressionBeforeOrderByX = "new (Key.GroupByFields, it as Grouping , new (Count() as count__CompanyName, Min(TEntity__.EmployeeNumber) as min__Number, Max(TEntity__.EmployeeNumber) as max__Number, Average(TEntity__.EmployeeNumber) as average__Number, Sum(TEntity__.EmployeeNumber) as sum__Number) as Aggregates)";
46+
var selectQ = group.Select(selectExpressionBeforeOrderByX);
47+
Assert.NotNull(selectQ);
48+
49+
var resultSelect = selectQ.ToDynamicList();
50+
Assert.NotNull(resultSelect);
51+
}
52+
953
/// <summary>
1054
/// The purpose of this test is to verify that after a group by of a dynamically created
1155
/// key, the Select clause can access the key's members
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Collections.Generic;
2+
3+
namespace System.Linq.Dynamic.Core.Tests.Entities
4+
{
5+
public class Company : Entity
6+
{
7+
public string Name { get; set; }
8+
9+
public long? MainCompanyId { get; set; }
10+
11+
public MainCompany MainCompany { get; set; }
12+
13+
public ICollection<Employee> Employees { get; set; }
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Collections.Generic;
2+
3+
namespace System.Linq.Dynamic.Core.Tests.Entities
4+
{
5+
public class Country : Entity
6+
{
7+
public string Code { get; set; }
8+
9+
public string Name { get; set; }
10+
11+
public ICollection<Employee> Employees { get; set; }
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace System.Linq.Dynamic.Core.Tests.Entities
2+
{
3+
public class Employee : Entity
4+
{
5+
public int EmployeeNumber { get; set; }
6+
7+
public string FirstName { get; set; }
8+
9+
public string LastName { get; set; }
10+
11+
public string Email { get; set; }
12+
13+
public DateTime HireDate { get; set; }
14+
15+
public long? CompanyId { get; set; }
16+
17+
public long? CountryId { get; set; }
18+
19+
public long? FunctionId { get; set; }
20+
21+
public long? SubFunctionId { get; set; }
22+
23+
public Company Company { get; set; }
24+
25+
public Country Country { get; set; }
26+
27+
public Function Function { get; set; }
28+
29+
public SubFunction SubFunction { get; set; }
30+
31+
public int? Assigned { get; set; }
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace System.Linq.Dynamic.Core.Tests.Entities
2+
{
3+
public abstract class Entity : IEntity
4+
{
5+
public long Id { get; set; }
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Collections.Generic;
2+
3+
namespace System.Linq.Dynamic.Core.Tests.Entities
4+
{
5+
public class Function : Entity
6+
{
7+
public string Code { get; set; }
8+
9+
public string Name { get; set; }
10+
11+
public ICollection<SubFunction> SubFunctions { get; set; }
12+
13+
public ICollection<Employee> Employees { get; set; }
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+

2+
namespace System.Linq.Dynamic.Core.Tests.Entities
3+
{
4+
public interface IEntity
5+
{
6+
long Id { get; set; }
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Collections.Generic;
2+
using System.ComponentModel.DataAnnotations.Schema;
3+
4+
namespace System.Linq.Dynamic.Core.Tests.Entities
5+
{
6+
[Table("KendoGrid_MainCompany")]
7+
public class MainCompany : Entity
8+
{
9+
public string Name { get; set; }
10+
11+
public ICollection<Company> Companies { get; set; }
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+

2+
namespace System.Linq.Dynamic.Core.Tests.Entities
3+
{
4+
public class OU : Entity
5+
{
6+
public string Code { get; set; }
7+
8+
public string Name { get; set; }
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+

2+
namespace System.Linq.Dynamic.Core.Tests.Entities
3+
{
4+
public class Product : Entity
5+
{
6+
public string Code { get; set; }
7+
8+
public string Name { get; set; }
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Collections.Generic;
2+
3+
namespace System.Linq.Dynamic.Core.Tests.Entities
4+
{
5+
public class Role : Entity
6+
{
7+
public string Name { get; set; }
8+
9+
public string Description { get; set; }
10+
11+
public ICollection<User> Users { get; set; }
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Collections.Generic;
2+
3+
namespace System.Linq.Dynamic.Core.Tests.Entities
4+
{
5+
public class SubFunction : Entity
6+
{
7+
public string Code { get; set; }
8+
9+
public string Name { get; set; }
10+
11+
public long? FunctionId { get; set; }
12+
13+
public Function Function { get; set; }
14+
15+
public ICollection<Employee> Employees { get; set; }
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Collections.Generic;
2+
3+
namespace System.Linq.Dynamic.Core.Tests.Entities
4+
{
5+
public class User : Entity
6+
{
7+
public string IdentityName { get; set; }
8+
9+
public string DisplayName { get; set; }
10+
11+
public string EmailAddress { get; set; }
12+
13+
public ICollection<Role> Roles { get; set; }
14+
15+
public bool HasRole(string role)
16+
{
17+
return Roles.Any(r => r.Name == role);
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)