Skip to content

Commit 54cd8a9

Browse files
Add comments
1 parent 74dce5b commit 54cd8a9

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/EntityFramework.DynamicFilters.Shared/LambdaToDbExpressionVisitor.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ private LambdaToDbExpressionVisitor(DynamicFilterDefinition filter, DbExpression
8080

8181
#region ExpressionVisitor Overrides
8282

83-
private ConstantExpression GetByteConstant(Expression expression)
83+
/// <summary>
84+
/// Attempts to try convert the expression into a byte. The expression must be a constant and in range of a byte.
85+
/// </summary>
86+
/// <param name="expression">The expression.</param>
87+
/// <returns>A expression converted to byte or null if the expression was not a constant or in range of a byte.</returns>
88+
private ConstantExpression TryGetByteConstant(Expression expression)
8489
{
8590
if (expression.NodeType != ExpressionType.Constant || expression.Type != typeof(int))
8691
return null;
@@ -94,6 +99,9 @@ private ConstantExpression GetByteConstant(Expression expression)
9499
return null;
95100
}
96101

102+
/// <summary>Gets inner operand.</summary>
103+
/// <param name="expression">The expression.</param>
104+
/// <returns>The inner operand.</returns>
97105
private Expression GetInnerOperand(Expression expression)
98106
{
99107
switch (expression.NodeType) {
@@ -110,6 +118,10 @@ private Expression GetInnerOperand(Expression expression)
110118
}
111119
}
112120

121+
/// <summary>If possible, we try to cast both side to byte otherwise we return the current BinaryExpression.</summary>
122+
/// <param name="node">The node.</param>
123+
/// <remarks>Pull: https://github.com/zzzprojects/EntityFramework.DynamicFilters/pull/164 </remarks>
124+
/// <returns>The BinaryExpression we try to cast both side to byte otherwise we return the current BinaryExpression.</returns>
113125
private BinaryExpression OptimizeByteEnumComparisons(BinaryExpression node)
114126
{
115127
if (node.Method != null)
@@ -136,12 +148,12 @@ private BinaryExpression OptimizeByteEnumComparisons(BinaryExpression node)
136148
if (leftIsByteEnum)
137149
leftOperand = Expression.Convert(leftOperand, typeof(byte));
138150
else
139-
leftOperand = GetByteConstant(leftOperand);
151+
leftOperand = TryGetByteConstant(leftOperand);
140152

141153
if (rightIsByteEnum)
142154
rightOperand = Expression.Convert(rightOperand, typeof(byte));
143155
else
144-
rightOperand = GetByteConstant(rightOperand);
156+
rightOperand = TryGetByteConstant(rightOperand);
145157

146158
if (leftOperand == null || rightOperand == null)
147159
return node;

src/EntityFramework.DynamicFilters.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "DynamicFiltersTests.Shared"
2525
EndProject
2626
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DynamicFiltersTests.NetStandard21", "DynamicFiltersTests.NetStandard21\DynamicFiltersTests.NetStandard21.csproj", "{89FAD78B-B06F-4A31-B9C0-E521803EE0E8}"
2727
EndProject
28+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Z.Lab", "Z.Lab\Z.Lab.csproj", "{9A4EB2AB-5FDC-4947-AC90-372E43383BC3}"
29+
EndProject
2830
Global
2931
GlobalSection(SharedMSBuildProjectFiles) = preSolution
3032
EntityFramework.DynamicFilters.Shared\EntityFramework.DynamicFilters.Shared.projitems*{13d421cd-5dc4-4287-b1b2-110a9cb5e07f}*SharedItemsImports = 13
@@ -57,6 +59,10 @@ Global
5759
{89FAD78B-B06F-4A31-B9C0-E521803EE0E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
5860
{89FAD78B-B06F-4A31-B9C0-E521803EE0E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
5961
{89FAD78B-B06F-4A31-B9C0-E521803EE0E8}.Release|Any CPU.Build.0 = Release|Any CPU
62+
{9A4EB2AB-5FDC-4947-AC90-372E43383BC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
63+
{9A4EB2AB-5FDC-4947-AC90-372E43383BC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
64+
{9A4EB2AB-5FDC-4947-AC90-372E43383BC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
65+
{9A4EB2AB-5FDC-4947-AC90-372E43383BC3}.Release|Any CPU.Build.0 = Release|Any CPU
6066
EndGlobalSection
6167
GlobalSection(SolutionProperties) = preSolution
6268
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)