Skip to content

Commit

Permalink
Update package 5.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavnavar committed Jan 24, 2024
1 parent 05d22dd commit d102d21
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 17 deletions.
2 changes: 1 addition & 1 deletion GridBlazor/GridBlazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<LangVersion>11.0</LangVersion>
<GenerateEmbeddedFilesManifest>True</GenerateEmbeddedFilesManifest>
<EnableDefaultEmbeddedResourceItems>False</EnableDefaultEmbeddedResourceItems>
<Version>5.0.8</Version>
<Version>5.0.9</Version>
<Title>GridBlazor</Title>
<Description>Grid components for Blazor</Description>
<Summary>Grid components for Blazor</Summary>
Expand Down
2 changes: 1 addition & 1 deletion GridCore/GridCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<EnableDefaultEmbeddedResourceItems>False</EnableDefaultEmbeddedResourceItems>
<Product>GridCore</Product>
<PackageId>GridCore</PackageId>
<Version>7.0.5</Version>
<Version>7.0.6</Version>
<Title>GridCore</Title>
<Description>Grid core component</Description>
<Summary>Grid core component</Summary>
Expand Down
2 changes: 1 addition & 1 deletion GridMvc/GridMvc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<EnableDefaultEmbeddedResourceItems>False</EnableDefaultEmbeddedResourceItems>
<Product>GridMvc</Product>
<PackageId>GridMvcCore</PackageId>
<Version>7.0.5</Version>
<Version>7.0.6</Version>
<Title>GridMvc</Title>
<Description>ASP.NET MVC Grid component</Description>
<Summary>ASP.NET MVC Grid component</Summary>
Expand Down
54 changes: 49 additions & 5 deletions GridShared/Filtering/Types/FilterTypeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,25 @@ protected Expression GetFilterExpression<T, S>(Expression leftExpr, string value
case GridFilterType.GreaterThanOrEquals:
return Expression.GreaterThanOrEqual(leftExpr, valueExpr);
case GridFilterType.IsDuplicated:
Expression groupBy = GetGroupBy<T, S>(source, leftExpr);
Expression groupBy = GetDuplicatedGroupBy<T, S>(source, leftExpr);
MethodInfo methodInfo = typeof(Queryable).GetMethods()
.Single(r => r.Name == "Contains" && r.GetParameters().Length == 2)
.MakeGenericMethod(new Type[] { typeof(S) });
return Expression.Call(methodInfo, groupBy, leftExpr);
case GridFilterType.IsNotDuplicated:
groupBy = GetGroupBy<T, S>(source, leftExpr);
groupBy = GetNotDuplicatedGroupBy<T, S>(source, leftExpr);
methodInfo = typeof(Queryable).GetMethods()
.Single(r => r.Name == "Contains" && r.GetParameters().Length == 2)
.MakeGenericMethod(new Type[] { typeof(S) });
var expresion = Expression.Call(methodInfo, groupBy, leftExpr);
return Expression.Not(expresion);
return Expression.Call(methodInfo, groupBy, leftExpr);
default:
throw new ArgumentOutOfRangeException();
}
}

#endregion

protected Expression GetGroupBy<T, S>(Expression source, Expression expression)
protected Expression GetDuplicatedGroupBy<T, S>(Expression source, Expression expression)
{
if (expression == null)
return null;
Expand Down Expand Up @@ -146,6 +145,51 @@ protected Expression GetGroupBy<T, S>(Expression source, Expression expression)
return binaryExpression;
}

protected Expression GetNotDuplicatedGroupBy<T, S>(Expression source, Expression expression)
{
if (expression == null)
return null;

List<string> names = new List<string>();
while (expression.NodeType != ExpressionType.Parameter)
{
names.Add(((MemberExpression)expression).Member.Name);
expression = ((MemberExpression)expression).Expression;
}

Type entityType = typeof(T);
ParameterExpression parameter = Expression.Parameter(entityType, "c");

Expression binaryExpression = parameter;
for (int i = names.Count - 1; i >= 0; i--)
{
binaryExpression = Expression.Property(binaryExpression, names[i]);
}

var selector = Expression.Lambda<Func<T, S>>(binaryExpression, parameter);

var methodInfo = typeof(Queryable).GetMethods()
.Single(r => r.Name == "GroupBy" && r.GetParameters().Length == 2)
.MakeGenericMethod(new Type[] { typeof(T), typeof(S) });
binaryExpression = Expression.Call(methodInfo, source, selector);

methodInfo = typeof(Queryable).GetMethods()
.Where(r => r.Name == "Where" && r.GetParameters().Length == 2)
.First()
.MakeGenericMethod(new Type[] { typeof(IGrouping<S, T>) }); ;
Expression<Func<IGrouping<S, T>, bool>> having = c => c.Count() <= 1;
binaryExpression = Expression.Call(methodInfo, binaryExpression, having);

methodInfo = typeof(Queryable).GetMethods()
.Where(r => r.Name == "Select" && r.GetParameters().Length == 2)
.First()
.MakeGenericMethod(new Type[] { typeof(IGrouping<S, T>), typeof(S) });
Expression<Func<IGrouping<S, T>, S>> select = c => c.Key;
binaryExpression = Expression.Call(methodInfo, binaryExpression, select);

return binaryExpression;
}

#region OData

public virtual string GetFilterExpression(string columnName, string value, GridFilterType filterType)
Expand Down
7 changes: 3 additions & 4 deletions GridShared/Filtering/Types/GuidFilterType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,18 @@ public override Expression GetFilterExpression<T>(Expression leftExpr, string va
binaryExpression = GetCaseInsensitiveСomparation("EndsWith", toStringLeftExpr, valueExpr);
break;
case GridFilterType.IsDuplicated:
Expression groupBy = GetGroupBy<T, Guid>(source, leftExpr);
Expression groupBy = GetDuplicatedGroupBy<T, Guid>(source, leftExpr);
MethodInfo methodInfo = typeof(Queryable).GetMethods()
.Single(r => r.Name == "Contains" && r.GetParameters().Length == 2)
.MakeGenericMethod(new Type[] { typeof(Guid) });
binaryExpression = Expression.Call(methodInfo, groupBy, toStringLeftExpr);
break;
case GridFilterType.IsNotDuplicated:
groupBy = GetGroupBy<T, Guid>(source, leftExpr);
groupBy = GetNotDuplicatedGroupBy<T, Guid>(source, leftExpr);
methodInfo = typeof(Queryable).GetMethods()
.Single(r => r.Name == "Contains" && r.GetParameters().Length == 2)
.MakeGenericMethod(new Type[] { typeof(Guid) });
var expresion = Expression.Call(methodInfo, groupBy, toStringLeftExpr);
binaryExpression = Expression.Not(expresion);
binaryExpression = Expression.Call(methodInfo, groupBy, toStringLeftExpr);
break;
default:
throw new ArgumentOutOfRangeException();
Expand Down
7 changes: 3 additions & 4 deletions GridShared/Filtering/Types/TextFilterType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,18 @@ public override Expression GetFilterExpression<T>(Expression leftExpr, string va
binaryExpression = GetCaseInsensitiveСomparation("EndsWith", leftExpr, valueExpr, removeDiacritics);
break;
case GridFilterType.IsDuplicated:
Expression groupBy = GetGroupBy<T, string>(source, leftExpr);
Expression groupBy = GetDuplicatedGroupBy<T, string>(source, leftExpr);
MethodInfo methodInfo = typeof(Queryable).GetMethods()
.Single(r => r.Name == "Contains" && r.GetParameters().Length == 2)
.MakeGenericMethod(new Type[] { typeof(string) });
binaryExpression = Expression.Call(methodInfo, groupBy, leftExpr);
break;
case GridFilterType.IsNotDuplicated:
groupBy = GetGroupBy<T, string>(source, leftExpr);
groupBy = GetNotDuplicatedGroupBy<T, string>(source, leftExpr);
methodInfo = typeof(Queryable).GetMethods()
.Single(r => r.Name == "Contains" && r.GetParameters().Length == 2)
.MakeGenericMethod(new Type[] { typeof(string) });
var expresion = Expression.Call(methodInfo, groupBy, leftExpr);
binaryExpression = Expression.Not(expresion);
binaryExpression = Expression.Call(methodInfo, groupBy, leftExpr);
break;
default:
throw new ArgumentOutOfRangeException();
Expand Down
2 changes: 1 addition & 1 deletion GridShared/GridShared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<LangVersion>11.0</LangVersion>
<Version>7.0.4</Version>
<Version>7.0.5</Version>
<Title>GridShared</Title>
<Description>Support library for GridBlazor and GridMvcCore component libraries</Description>
<Summary>Support library for GridBlazor and GridMvcCore component libraries</Summary>
Expand Down

0 comments on commit d102d21

Please sign in to comment.