column in Columns)
{
- @if (IsEditMode && column.EditorTemplate != null)
+ @if (IsEditMode && column.EditTemplate != null)
{
- @column.EditorTemplate(item)
+ @column.EditTemplate(item)
}
else
{
diff --git a/src/BlazorTable/Components/Table.razor.cs b/src/BlazorTable/Components/Table.razor.cs
index d6ded043..04c1d77c 100644
--- a/src/BlazorTable/Components/Table.razor.cs
+++ b/src/BlazorTable/Components/Table.razor.cs
@@ -72,11 +72,11 @@ private IEnumerable GetData()
{
if (sortColumn.SortDescending)
{
- query = query.OrderByDescending(sortColumn.Property);
+ query = query.OrderByDescending(sortColumn.Field);
}
else
{
- query = query.OrderBy(sortColumn.Property);
+ query = query.OrderBy(sortColumn.Field);
}
}
diff --git a/src/BlazorTable/Filters/BooleanFilter.razor.cs b/src/BlazorTable/Filters/BooleanFilter.razor.cs
index 9b69b68c..b6fd88cc 100644
--- a/src/BlazorTable/Filters/BooleanFilter.razor.cs
+++ b/src/BlazorTable/Filters/BooleanFilter.razor.cs
@@ -62,26 +62,26 @@ public Expression> GetFilter()
case BooleanCondition.True:
return Expression.Lambda>(
Expression.AndAlso(
- Expression.NotEqual(Column.Property.Body, Expression.Constant(null)),
- Expression.IsTrue(Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()))),
- Column.Property.Parameters);
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
+ Expression.IsTrue(Expression.Convert(Column.Field.Body, Column.Type.GetNonNullableType()))),
+ Column.Field.Parameters);
case BooleanCondition.False:
return Expression.Lambda>(
Expression.AndAlso(
- Expression.NotEqual(Column.Property.Body, Expression.Constant(null)),
- Expression.IsFalse(Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()))),
- Column.Property.Parameters);
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
+ Expression.IsFalse(Expression.Convert(Column.Field.Body, Column.Type.GetNonNullableType()))),
+ Column.Field.Parameters);
case BooleanCondition.IsNull:
return Expression.Lambda>(
- Expression.Equal(Column.Property.Body, Expression.Constant(null)),
- Column.Property.Parameters);
+ Expression.Equal(Column.Field.Body, Expression.Constant(null)),
+ Column.Field.Parameters);
case BooleanCondition.IsNotNull:
return Expression.Lambda>(
- Expression.NotEqual(Column.Property.Body, Expression.Constant(null)),
- Column.Property.Parameters);
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
+ Column.Field.Parameters);
}
return null;
diff --git a/src/BlazorTable/Filters/DateFilter.razor.cs b/src/BlazorTable/Filters/DateFilter.razor.cs
index 0f202ba0..00428262 100644
--- a/src/BlazorTable/Filters/DateFilter.razor.cs
+++ b/src/BlazorTable/Filters/DateFilter.razor.cs
@@ -76,66 +76,66 @@ public Expression> GetFilter()
case NumberCondition.IsEqualTo:
return Expression.Lambda>(
Expression.AndAlso(
- Expression.NotEqual(Column.Property.Body, Expression.Constant(null)),
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
Expression.Equal(
- Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()),
+ Expression.Convert(Column.Field.Body, Column.Type.GetNonNullableType()),
Expression.Constant(FilterValue))),
- Column.Property.Parameters);
+ Column.Field.Parameters);
case NumberCondition.IsNotEqualTo:
return Expression.Lambda>(
Expression.AndAlso(
- Expression.NotEqual(Column.Property.Body, Expression.Constant(null)),
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
Expression.NotEqual(
- Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()),
+ Expression.Convert(Column.Field.Body, Column.Type.GetNonNullableType()),
Expression.Constant(FilterValue))),
- Column.Property.Parameters);
+ Column.Field.Parameters);
case NumberCondition.IsGreaterThanOrEqualTo:
return Expression.Lambda>(
Expression.AndAlso(
- Expression.NotEqual(Column.Property.Body, Expression.Constant(null)),
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
Expression.GreaterThanOrEqual(
- Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()),
+ Expression.Convert(Column.Field.Body, Column.Type.GetNonNullableType()),
Expression.Constant(FilterValue))),
- Column.Property.Parameters);
+ Column.Field.Parameters);
case NumberCondition.IsGreaterThan:
return Expression.Lambda>(
Expression.AndAlso(
- Expression.NotEqual(Column.Property.Body, Expression.Constant(null)),
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
Expression.GreaterThan(
- Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()),
+ Expression.Convert(Column.Field.Body, Column.Type.GetNonNullableType()),
Expression.Constant(FilterValue))),
- Column.Property.Parameters);
+ Column.Field.Parameters);
case NumberCondition.IsLessThanOrEqualTo:
return Expression.Lambda>(
Expression.AndAlso(
- Expression.NotEqual(Column.Property.Body, Expression.Constant(null)),
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
Expression.LessThanOrEqual(
- Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()),
+ Expression.Convert(Column.Field.Body, Column.Type.GetNonNullableType()),
Expression.Constant(FilterValue))),
- Column.Property.Parameters);
+ Column.Field.Parameters);
case NumberCondition.IsLessThan:
return Expression.Lambda>(
Expression.AndAlso(
- Expression.NotEqual(Column.Property.Body, Expression.Constant(null)),
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
Expression.LessThan(
- Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()),
+ Expression.Convert(Column.Field.Body, Column.Type.GetNonNullableType()),
Expression.Constant(FilterValue))),
- Column.Property.Parameters);
+ Column.Field.Parameters);
case NumberCondition.IsNull:
return Expression.Lambda>(
- Expression.Equal(Column.Property.Body, Expression.Constant(null)),
- Column.Property.Parameters);
+ Expression.Equal(Column.Field.Body, Expression.Constant(null)),
+ Column.Field.Parameters);
case NumberCondition.IsNotNull:
return Expression.Lambda>(
- Expression.NotEqual(Column.Property.Body, Expression.Constant(null)),
- Column.Property.Parameters);
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
+ Column.Field.Parameters);
default:
throw new ArgumentException(Condition + " is not defined!");
diff --git a/src/BlazorTable/Filters/NumberFilter.razor.cs b/src/BlazorTable/Filters/NumberFilter.razor.cs
index 820e7908..269606e8 100644
--- a/src/BlazorTable/Filters/NumberFilter.razor.cs
+++ b/src/BlazorTable/Filters/NumberFilter.razor.cs
@@ -77,66 +77,66 @@ public Expression> GetFilter()
case NumberCondition.IsEqualTo:
return Expression.Lambda>(
Expression.AndAlso(
- Expression.NotEqual(Column.Property.Body, Expression.Constant(null)),
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
Expression.Equal(
- Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()),
+ Expression.Convert(Column.Field.Body, Column.Type.GetNonNullableType()),
Expression.Constant(Convert.ChangeType(FilterValue, Column.Type.GetNonNullableType(), CultureInfo.InvariantCulture)))),
- Column.Property.Parameters);
+ Column.Field.Parameters);
case NumberCondition.IsNotEqualTo:
return Expression.Lambda>(
Expression.AndAlso(
- Expression.NotEqual(Column.Property.Body, Expression.Constant(null)),
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
Expression.NotEqual(
- Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()),
+ Expression.Convert(Column.Field.Body, Column.Type.GetNonNullableType()),
Expression.Constant(Convert.ChangeType(FilterValue, Column.Type.GetNonNullableType(), CultureInfo.InvariantCulture)))),
- Column.Property.Parameters);
+ Column.Field.Parameters);
case NumberCondition.IsGreaterThanOrEqualTo:
return Expression.Lambda>(
Expression.AndAlso(
- Expression.NotEqual(Column.Property.Body, Expression.Constant(null)),
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
Expression.GreaterThanOrEqual(
- Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()),
+ Expression.Convert(Column.Field.Body, Column.Type.GetNonNullableType()),
Expression.Constant(Convert.ChangeType(FilterValue, Column.Type.GetNonNullableType(), CultureInfo.InvariantCulture)))),
- Column.Property.Parameters);
+ Column.Field.Parameters);
case NumberCondition.IsGreaterThan:
return Expression.Lambda>(
Expression.AndAlso(
- Expression.NotEqual(Column.Property.Body, Expression.Constant(null)),
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
Expression.GreaterThan(
- Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()),
+ Expression.Convert(Column.Field.Body, Column.Type.GetNonNullableType()),
Expression.Constant(Convert.ChangeType(FilterValue, Column.Type.GetNonNullableType(), CultureInfo.InvariantCulture)))),
- Column.Property.Parameters);
+ Column.Field.Parameters);
case NumberCondition.IsLessThanOrEqualTo:
return Expression.Lambda>(
Expression.AndAlso(
- Expression.NotEqual(Column.Property.Body, Expression.Constant(null)),
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
Expression.LessThanOrEqual(
- Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()),
+ Expression.Convert(Column.Field.Body, Column.Type.GetNonNullableType()),
Expression.Constant(Convert.ChangeType(FilterValue, Column.Type.GetNonNullableType(), CultureInfo.InvariantCulture)))),
- Column.Property.Parameters);
+ Column.Field.Parameters);
case NumberCondition.IsLessThan:
return Expression.Lambda>(
Expression.AndAlso(
- Expression.NotEqual(Column.Property.Body, Expression.Constant(null)),
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
Expression.LessThan(
- Expression.Convert(Column.Property.Body, Column.Type.GetNonNullableType()),
+ Expression.Convert(Column.Field.Body, Column.Type.GetNonNullableType()),
Expression.Constant(Convert.ChangeType(FilterValue, Column.Type.GetNonNullableType(), CultureInfo.InvariantCulture)))),
- Column.Property.Parameters);
+ Column.Field.Parameters);
case NumberCondition.IsNull:
return Expression.Lambda>(
- Expression.Equal(Column.Property.Body, Expression.Constant(null)),
- Column.Property.Parameters);
+ Expression.Equal(Column.Field.Body, Expression.Constant(null)),
+ Column.Field.Parameters);
case NumberCondition.IsNotNull:
return Expression.Lambda>(
- Expression.NotEqual(Column.Property.Body, Expression.Constant(null)),
- Column.Property.Parameters);
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
+ Column.Field.Parameters);
default:
throw new ArgumentException(Condition + " is not defined!");
}
diff --git a/src/BlazorTable/Filters/StringFilter.razor.cs b/src/BlazorTable/Filters/StringFilter.razor.cs
index 5f7ca11c..dbb3672a 100644
--- a/src/BlazorTable/Filters/StringFilter.razor.cs
+++ b/src/BlazorTable/Filters/StringFilter.razor.cs
@@ -97,25 +97,25 @@ private StringCondition GetConditionFromMethod(string method, bool not)
public Expression> GetFilter()
{
FilterText = FilterText?.Trim();
-
+
switch (Condition)
{
case StringCondition.Contains:
- return Utillities.CallMethodType(Column.Property, typeof(string), nameof(string.Contains), typeof(string), FilterText);
+ return Utillities.CallMethodType(Column.Field, typeof(string), nameof(string.Contains), typeof(string), FilterText);
case StringCondition.DoesNotContain:
- return Utillities.CallMethodType(Column.Property, typeof(string), nameof(string.Contains), typeof(string), FilterText).Not();
+ return Utillities.CallMethodType(Column.Field, typeof(string), nameof(string.Contains), typeof(string), FilterText).Not();
case StringCondition.StartsWith:
- return Utillities.CallMethodType(Column.Property, typeof(string), nameof(string.StartsWith), typeof(string), FilterText);
+ return Utillities.CallMethodType(Column.Field, typeof(string), nameof(string.StartsWith), typeof(string), FilterText);
case StringCondition.EndsWith:
- return Utillities.CallMethodType(Column.Property, typeof(string), nameof(string.EndsWith), typeof(string), FilterText);
+ return Utillities.CallMethodType(Column.Field, typeof(string), nameof(string.EndsWith), typeof(string), FilterText);
case StringCondition.IsEqualTo:
- return Utillities.CallMethodType(Column.Property, typeof(string), nameof(string.Equals), typeof(string), FilterText);
+ return Utillities.CallMethodType(Column.Field, typeof(string), nameof(string.Equals), typeof(string), FilterText);
case StringCondition.IsNotEqualTo:
- return Utillities.CallMethodType(Column.Property, typeof(string), nameof(string.Equals), typeof(string), FilterText).Not();
+ return Utillities.CallMethodType(Column.Field, typeof(string), nameof(string.Equals), typeof(string), FilterText).Not();
case StringCondition.IsNullOrEmpty:
- return Utillities.CallMethodTypeStaticSelf(Column.Property, typeof(string), nameof(string.IsNullOrEmpty), typeof(string));
+ return Utillities.CallMethodTypeStaticSelf(Column.Field, typeof(string), nameof(string.IsNullOrEmpty), typeof(string));
case StringCondition.IsNotNulOrEmpty:
- return Utillities.CallMethodTypeStaticSelf(Column.Property, typeof(string), nameof(string.IsNullOrEmpty), typeof(string)).Not();
+ return Utillities.CallMethodTypeStaticSelf(Column.Field, typeof(string), nameof(string.IsNullOrEmpty), typeof(string)).Not();
default:
throw new ArgumentException(Condition + " is not defined!");
}
diff --git a/src/BlazorTable/Interfaces/IColumn.cs b/src/BlazorTable/Interfaces/IColumn.cs
index 1cd6f41c..507efd52 100644
--- a/src/BlazorTable/Interfaces/IColumn.cs
+++ b/src/BlazorTable/Interfaces/IColumn.cs
@@ -52,11 +52,11 @@ public interface IColumn
Type Type { get; }
///
- /// Property which this column is for
+ /// Field which this column is for
/// Required when Sortable = true
/// Required when Filterable = true
///
- Expression> Property { get; set; }
+ Expression> Field { get; set; }
///
/// Filter expression
@@ -66,7 +66,7 @@ public interface IColumn
///
/// Edit Mode Item Template
///
- RenderFragment EditorTemplate { get; set; }
+ RenderFragment EditTemplate { get; set; }
///
/// Normal Item Template
diff --git a/src/BlazorTable/Interfaces/ITable.cs b/src/BlazorTable/Interfaces/ITable.cs
index bfcf6166..2aecf575 100644
--- a/src/BlazorTable/Interfaces/ITable.cs
+++ b/src/BlazorTable/Interfaces/ITable.cs
@@ -46,7 +46,7 @@ public interface ITable
void LastPage();
///
- /// Redraws the Table using EditorTemplate instead of Template
+ /// Redraws the Table using EditTemplate instead of Template
///
void ToggleEditMode();
From 30e785404067aad8ec6a40ce3fa97410e371a16e Mon Sep 17 00:00:00 2001
From: Ivan Josipovic <9521987+IvanJosipovic@users.noreply.github.com>
Date: Thu, 24 Oct 2019 22:07:32 -0700
Subject: [PATCH 06/11] Updated readme
---
README.md | 3 +++
1 file changed, 3 insertions(+)
diff --git a/README.md b/README.md
index 8a8b6808..37ba222a 100644
--- a/README.md
+++ b/README.md
@@ -20,6 +20,9 @@ A simple Table Control for Blazor
- Dates
- Custom Component
## Todo
+- Client Side
+ - Filtering
+ - Enums
- Remove dependency on Bootstrap + BlazorStrap
From 3c315272f12f1308c9af570d8a41ab3b7dd78d72 Mon Sep 17 00:00:00 2001
From: Ivan Josipovic <9521987+IvanJosipovic@users.noreply.github.com>
Date: Fri, 25 Oct 2019 22:54:37 -0700
Subject: [PATCH 07/11] misc cleanup
---
src/BlazorTable/Components/Table.razor.cs | 4 ++--
src/BlazorTable/Filters/DateFilter.razor.cs | 2 +-
src/BlazorTable/Filters/NumberFilter.razor.cs | 2 +-
src/BlazorTable/Utillities.cs | 15 ++++++---------
4 files changed, 10 insertions(+), 13 deletions(-)
diff --git a/src/BlazorTable/Components/Table.razor.cs b/src/BlazorTable/Components/Table.razor.cs
index 04c1d77c..a4435d7a 100644
--- a/src/BlazorTable/Components/Table.razor.cs
+++ b/src/BlazorTable/Components/Table.razor.cs
@@ -28,7 +28,7 @@ public partial class Table : ITable
[Parameter]
public IEnumerable Items { get; set; }
- [Inject] ILogger> Logger { get; set; }
+ [Inject] private ILogger> Logger { get; set; }
private IEnumerable TempItems { get; set; }
@@ -66,7 +66,7 @@ private IEnumerable GetData()
TotalCount = query.Count();
- var sortColumn = Columns.FirstOrDefault(x => x.SortColumn);
+ var sortColumn = Columns.Find(x => x.SortColumn);
if (sortColumn != null)
{
diff --git a/src/BlazorTable/Filters/DateFilter.razor.cs b/src/BlazorTable/Filters/DateFilter.razor.cs
index 00428262..f76698b5 100644
--- a/src/BlazorTable/Filters/DateFilter.razor.cs
+++ b/src/BlazorTable/Filters/DateFilter.razor.cs
@@ -60,7 +60,7 @@ protected override void OnInitialized()
}
}
- if (binaryExpression.Right is BinaryExpression binaryExpression2
+ if (binaryExpression.Right is BinaryExpression binaryExpression2
&& binaryExpression2.Right is ConstantExpression constantExpression)
{
FilterValue = DateTime.Parse(constantExpression.Value.ToString(), CultureInfo.InvariantCulture);
diff --git a/src/BlazorTable/Filters/NumberFilter.razor.cs b/src/BlazorTable/Filters/NumberFilter.razor.cs
index 269606e8..df7a32fa 100644
--- a/src/BlazorTable/Filters/NumberFilter.razor.cs
+++ b/src/BlazorTable/Filters/NumberFilter.razor.cs
@@ -61,7 +61,7 @@ protected override void OnInitialized()
}
}
- if (binaryExpression.Right is BinaryExpression binaryExpression2
+ if (binaryExpression.Right is BinaryExpression binaryExpression2
&& binaryExpression2.Right is ConstantExpression constantExpression)
{
FilterValue = constantExpression.Value.ToString();
diff --git a/src/BlazorTable/Utillities.cs b/src/BlazorTable/Utillities.cs
index b0e1f27c..beb850cc 100644
--- a/src/BlazorTable/Utillities.cs
+++ b/src/BlazorTable/Utillities.cs
@@ -40,7 +40,6 @@ public static bool IsNumeric(this Type type)
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
{
return Nullable.GetUnderlyingType(type).IsNumeric();
- //return IsNumeric(Nullable.GetUnderlyingType(type));
}
return false;
default:
@@ -86,23 +85,21 @@ public static Expression> CallMethodType(Expression> CallMethodType(Expression> expression, Type type, string method, Type[] parameters, object[] values)
{
- MethodInfo methodInfo = type.GetMethod(method, parameters);
-
return Expression.Lambda>(
Expression.Call(
expression.Body,
- methodInfo,
+ type.GetMethod(method, parameters),
values.OrEmptyIfNull().Select(Expression.Constant)),
expression.Parameters);
}
public static Expression> CallMethodTypeStaticSelf(Expression> expression, Type type, string method, Type parameter)
{
- MethodInfo methodInfo = type.GetMethod(method, new[] { parameter });
-
- var call = Expression.Call(methodInfo, expression.Body);
-
- return Expression.Lambda>(call, expression.Parameters);
+ return Expression.Lambda>(
+ Expression.Call(
+ type.GetMethod(method, new[] { parameter }),
+ expression.Body),
+ expression.Parameters);
}
public static Type GetMemberUnderlyingType(this MemberInfo member)
From 81e8919612eb16d00e4479a9d85c2860e6c937ac Mon Sep 17 00:00:00 2001
From: Ivan Josipovic <9521987+IvanJosipovic@users.noreply.github.com>
Date: Fri, 25 Oct 2019 22:58:32 -0700
Subject: [PATCH 08/11] removed this
---
src/BlazorTable/Components/Column.razor.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/BlazorTable/Components/Column.razor.cs b/src/BlazorTable/Components/Column.razor.cs
index c606749e..f2af0cfd 100644
--- a/src/BlazorTable/Components/Column.razor.cs
+++ b/src/BlazorTable/Components/Column.razor.cs
@@ -53,7 +53,7 @@ public string Title
public void Dispose()
{
- this.Table.RemoveColumn(this);
+ Table.RemoveColumn(this);
}
protected override void OnInitialized()
From 6b11f0749ffaf839215b8bddc720c16865a70e62 Mon Sep 17 00:00:00 2001
From: Ivan Josipovic <9521987+IvanJosipovic@users.noreply.github.com>
Date: Fri, 25 Oct 2019 23:03:20 -0700
Subject: [PATCH 09/11] switched to v1 github actions
---
.github/workflows/cicd.yml | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml
index 8ea185fe..960be956 100644
--- a/.github/workflows/cicd.yml
+++ b/.github/workflows/cicd.yml
@@ -10,9 +10,9 @@ jobs:
timeout-minutes: 10
steps:
- name: Checkout code
- uses: actions/checkout@master
+ uses: actions/checkout@v1
- name: Setup .NET Core
- uses: actions/setup-dotnet@master
+ uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.2.402
- name: SonarQube Install
@@ -22,7 +22,7 @@ jobs:
env:
SONARQUBE_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
- name: Setup .NET Core
- uses: actions/setup-dotnet@master
+ uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.100-preview1-014459
- name: Dotnet Build
@@ -31,7 +31,7 @@ jobs:
working-directory: src/BlazorTable.Sample
run: dotnet publish --configuration Release
- name: Setup .NET Core
- uses: actions/setup-dotnet@master
+ uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.2.402
- name: SonarQube End
From 26f97b3312c6077b28689426f6ea1fbb658c930b Mon Sep 17 00:00:00 2001
From: Ivan Josipovic <9521987+IvanJosipovic@users.noreply.github.com>
Date: Sat, 26 Oct 2019 12:50:03 -0700
Subject: [PATCH 10/11] StringFilter is no longer case sensitive
---
src/BlazorTable/Filters/StringFilter.razor.cs | 114 ++++++++++++++----
src/BlazorTable/Utillities.cs | 29 -----
2 files changed, 91 insertions(+), 52 deletions(-)
diff --git a/src/BlazorTable/Filters/StringFilter.razor.cs b/src/BlazorTable/Filters/StringFilter.razor.cs
index dbb3672a..67d222ee 100644
--- a/src/BlazorTable/Filters/StringFilter.razor.cs
+++ b/src/BlazorTable/Filters/StringFilter.razor.cs
@@ -28,29 +28,33 @@ protected override void OnInitialized()
{
bool NotCondition = false;
- Expression method;
+ Expression method = Column.Filter.Body;
- if (Column.Filter.Body is UnaryExpression unary)
+ if (method is BinaryExpression binary)
{
- NotCondition = unary.NodeType == ExpressionType.Not;
+ method = binary.Right;
+ }
- method = unary.Operand;
+ if (method is BinaryExpression binary2)
+ {
+ NotCondition = binary2.NodeType == ExpressionType.LessThanOrEqual;
+ method = binary2.Left;
}
- else
+
+ if (method is UnaryExpression unary1)
{
- method = Column.Filter.Body;
+ NotCondition = unary1.NodeType == ExpressionType.Not;
+ method = unary1.Operand;
}
if (method is MethodCallExpression methodCall)
{
- var MethodName = methodCall.Method.Name;
-
- if (methodCall.Arguments[0] != null && methodCall.Arguments[0] is ConstantExpression constantExpression)
+ if (methodCall.Arguments[0] is ConstantExpression constantExpression)
{
- FilterText = constantExpression.Value.ToString();
+ FilterText = constantExpression.Value?.ToString();
}
- Condition = GetConditionFromMethod(MethodName, NotCondition);
+ Condition = GetConditionFromMethod(methodCall.Method.Name, NotCondition);
}
}
}
@@ -58,11 +62,11 @@ protected override void OnInitialized()
private StringCondition GetConditionFromMethod(string method, bool not)
{
- if (method == nameof(string.Contains) && !not)
+ if (method == nameof(string.IndexOf) && !not)
{
return StringCondition.Contains;
}
- else if (method == nameof(string.Contains) && not)
+ else if (method == nameof(string.IndexOf) && not)
{
return StringCondition.DoesNotContain;
}
@@ -88,7 +92,7 @@ private StringCondition GetConditionFromMethod(string method, bool not)
}
else if (method == nameof(string.IsNullOrEmpty) && not)
{
- return StringCondition.IsNullOrEmpty;
+ return StringCondition.IsNotNulOrEmpty;
}
throw new InvalidOperationException("Shouldn't be here");
@@ -97,25 +101,89 @@ private StringCondition GetConditionFromMethod(string method, bool not)
public Expression> GetFilter()
{
FilterText = FilterText?.Trim();
-
+
switch (Condition)
{
case StringCondition.Contains:
- return Utillities.CallMethodType(Column.Field, typeof(string), nameof(string.Contains), typeof(string), FilterText);
+ return Expression.Lambda>(
+ Expression.AndAlso(
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
+ Expression.GreaterThanOrEqual(
+ Expression.Call(
+ Column.Field.Body,
+ typeof(string).GetMethod(nameof(string.IndexOf), new[] { typeof(string), typeof(StringComparison) }),
+ new[] { Expression.Constant(FilterText), Expression.Constant(StringComparison.OrdinalIgnoreCase) }),
+ Expression.Constant(0))),
+ Column.Field.Parameters);
+
case StringCondition.DoesNotContain:
- return Utillities.CallMethodType(Column.Field, typeof(string), nameof(string.Contains), typeof(string), FilterText).Not();
+ return Expression.Lambda>(
+ Expression.AndAlso(
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
+ Expression.LessThanOrEqual(
+ Expression.Call(
+ Column.Field.Body,
+ typeof(string).GetMethod(nameof(string.IndexOf), new[] { typeof(string), typeof(StringComparison) }),
+ new[] { Expression.Constant(FilterText), Expression.Constant(StringComparison.OrdinalIgnoreCase) }),
+ Expression.Constant(-1))),
+ Column.Field.Parameters);
+
case StringCondition.StartsWith:
- return Utillities.CallMethodType(Column.Field, typeof(string), nameof(string.StartsWith), typeof(string), FilterText);
+ return Expression.Lambda>(
+ Expression.AndAlso(
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
+ Expression.Call(
+ Column.Field.Body,
+ typeof(string).GetMethod(nameof(string.StartsWith), new[] { typeof(string), typeof(StringComparison) }),
+ new[] { Expression.Constant(FilterText), Expression.Constant(StringComparison.OrdinalIgnoreCase) })),
+ Column.Field.Parameters);
+
case StringCondition.EndsWith:
- return Utillities.CallMethodType(Column.Field, typeof(string), nameof(string.EndsWith), typeof(string), FilterText);
+ return Expression.Lambda>(
+ Expression.AndAlso(
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
+ Expression.Call(
+ Column.Field.Body,
+ typeof(string).GetMethod(nameof(string.EndsWith), new[] { typeof(string), typeof(StringComparison) }),
+ new[] { Expression.Constant(FilterText), Expression.Constant(StringComparison.OrdinalIgnoreCase) })),
+ Column.Field.Parameters);
+
case StringCondition.IsEqualTo:
- return Utillities.CallMethodType(Column.Field, typeof(string), nameof(string.Equals), typeof(string), FilterText);
+ return Expression.Lambda>(
+ Expression.AndAlso(
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
+ Expression.Call(
+ Column.Field.Body,
+ typeof(string).GetMethod(nameof(string.Equals), new[] { typeof(string), typeof(StringComparison) }),
+ new[] { Expression.Constant(FilterText), Expression.Constant(StringComparison.OrdinalIgnoreCase) })),
+ Column.Field.Parameters);
+
case StringCondition.IsNotEqualTo:
- return Utillities.CallMethodType(Column.Field, typeof(string), nameof(string.Equals), typeof(string), FilterText).Not();
+ return Expression.Lambda>(
+ Expression.AndAlso(
+ Expression.NotEqual(Column.Field.Body, Expression.Constant(null)),
+ Expression.Not(
+ Expression.Call(
+ Column.Field.Body,
+ typeof(string).GetMethod(nameof(string.Equals), new[] { typeof(string), typeof(StringComparison) }),
+ new[] { Expression.Constant(FilterText), Expression.Constant(StringComparison.OrdinalIgnoreCase) }))),
+ Column.Field.Parameters);
+
case StringCondition.IsNullOrEmpty:
- return Utillities.CallMethodTypeStaticSelf(Column.Field, typeof(string), nameof(string.IsNullOrEmpty), typeof(string));
+ return Expression.Lambda>(
+ Expression.Call(
+ typeof(string).GetMethod(nameof(string.IsNullOrEmpty), new[] { typeof(string)}),
+ Column.Field.Body),
+ Column.Field.Parameters);
+
case StringCondition.IsNotNulOrEmpty:
- return Utillities.CallMethodTypeStaticSelf(Column.Field, typeof(string), nameof(string.IsNullOrEmpty), typeof(string)).Not();
+ return Expression.Lambda>(
+ Expression.Not(
+ Expression.Call(
+ typeof(string).GetMethod(nameof(string.IsNullOrEmpty), new[] { typeof(string)}),
+ Column.Field.Body)),
+ Column.Field.Parameters);
+
default:
throw new ArgumentException(Condition + " is not defined!");
}
diff --git a/src/BlazorTable/Utillities.cs b/src/BlazorTable/Utillities.cs
index beb850cc..625b0970 100644
--- a/src/BlazorTable/Utillities.cs
+++ b/src/BlazorTable/Utillities.cs
@@ -78,30 +78,6 @@ public static string GetDescription(this T e) where T : IConvertible
return null; // could also return string.Empty
}
- public static Expression> CallMethodType(Expression> expression, Type type, string method, Type parameter, object value)
- {
- return CallMethodType(expression, type, method, new[] { parameter }, new[] { value });
- }
-
- public static Expression> CallMethodType(Expression> expression, Type type, string method, Type[] parameters, object[] values)
- {
- return Expression.Lambda>(
- Expression.Call(
- expression.Body,
- type.GetMethod(method, parameters),
- values.OrEmptyIfNull().Select(Expression.Constant)),
- expression.Parameters);
- }
-
- public static Expression> CallMethodTypeStaticSelf(Expression> expression, Type type, string method, Type parameter)
- {
- return Expression.Lambda>(
- Expression.Call(
- type.GetMethod(method, new[] { parameter }),
- expression.Body),
- expression.Parameters);
- }
-
public static Type GetMemberUnderlyingType(this MemberInfo member)
{
switch (member.MemberType)
@@ -132,10 +108,5 @@ public static MemberInfo GetPropertyMemberInfo(this Expression> Not(this Expression> expression)
- {
- return Expression.Lambda>(Expression.Not(expression.Body), expression.Parameters[0]);
- }
}
}
From 76ee58049aa973c128031a3402fd74d5934003fd Mon Sep 17 00:00:00 2001
From: Ivan Josipovic <9521987+IvanJosipovic@users.noreply.github.com>
Date: Sat, 26 Oct 2019 12:54:54 -0700
Subject: [PATCH 11/11] simplified logic
---
src/BlazorTable/Filters/StringFilter.razor.cs | 38 +++++++++++--------
1 file changed, 22 insertions(+), 16 deletions(-)
diff --git a/src/BlazorTable/Filters/StringFilter.razor.cs b/src/BlazorTable/Filters/StringFilter.razor.cs
index 67d222ee..605540a5 100644
--- a/src/BlazorTable/Filters/StringFilter.razor.cs
+++ b/src/BlazorTable/Filters/StringFilter.razor.cs
@@ -62,38 +62,44 @@ protected override void OnInitialized()
private StringCondition GetConditionFromMethod(string method, bool not)
{
- if (method == nameof(string.IndexOf) && !not)
+ if (not)
{
- return StringCondition.Contains;
+ if (method == nameof(string.IndexOf))
+ {
+ return StringCondition.DoesNotContain;
+ }
+ else if (method == nameof(string.Equals))
+ {
+ return StringCondition.IsNotEqualTo;
+ }
+ else if (method == nameof(string.IsNullOrEmpty))
+ {
+ return StringCondition.IsNotNulOrEmpty;
+ }
+
+ throw new InvalidOperationException("Shouldn't be here");
}
- else if (method == nameof(string.IndexOf) && not)
+
+ if (method == nameof(string.IndexOf))
{
- return StringCondition.DoesNotContain;
+ return StringCondition.Contains;
}
- else if (method == nameof(string.StartsWith) && !not)
+ else if (method == nameof(string.StartsWith))
{
return StringCondition.StartsWith;
}
- else if (method == nameof(string.EndsWith) && !not)
+ else if (method == nameof(string.EndsWith))
{
return StringCondition.EndsWith;
}
- else if (method == nameof(string.Equals) && !not)
+ else if (method == nameof(string.Equals))
{
return StringCondition.IsEqualTo;
}
- else if (method == nameof(string.Equals) && not)
- {
- return StringCondition.IsNotEqualTo;
- }
- else if (method == nameof(string.IsNullOrEmpty) && !not)
+ else if (method == nameof(string.IsNullOrEmpty))
{
return StringCondition.IsNullOrEmpty;
}
- else if (method == nameof(string.IsNullOrEmpty) && not)
- {
- return StringCondition.IsNotNulOrEmpty;
- }
throw new InvalidOperationException("Shouldn't be here");
}
|