-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added helper method to generate expression input which handles 'Not' …
…case
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
DynamicExpressionBuilder/Helpers/ExpressionBuilderHelpers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using DynamicExpressionBuilder.Enums; | ||
using DynamicExpressionBuilder.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace DynamicExpressionBuilder.Helpers | ||
{ | ||
|
||
/// <summary> | ||
/// Contains helper methods | ||
/// </summary> | ||
public class ExpressionBuilderHelpers | ||
{ | ||
|
||
/// <summary> | ||
/// Prepare ExpressionInput object. You can build your own logic to create ExpressionInput object. | ||
/// </summary> | ||
/// <param name="propertyName">Property Name</param> | ||
/// <param name="operation">Operation. Eg. .StartsWith(""), .Contains("")</param> | ||
/// <param name="value">Value to operate with</param> | ||
/// <param name="operand">Operand. And, Or, Not</param> | ||
/// <returns></returns> | ||
public static ExpressionInput GetExpressionInput(string propertyName, Operation operation, object value, QueryOperand operand) | ||
{ | ||
if (operand == QueryOperand.Not) | ||
return new ExpressionInput { Value = value, Operand = QueryOperand.And, Operation = Operation.NotEquals, PropertyName = propertyName }; | ||
else | ||
return new ExpressionInput { Value = value, Operand = operand, Operation = operation, PropertyName = propertyName }; | ||
|
||
} | ||
} | ||
} |