Skip to content

Commit

Permalink
Added helper method to generate expression input which handles 'Not' …
Browse files Browse the repository at this point in the history
…case
  • Loading branch information
janaks09 committed Jan 22, 2018
1 parent 6bf8db9 commit 37fe67b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
7 changes: 6 additions & 1 deletion DynamicExpressionBuilder/Enums/QueryOperand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public enum QueryOperand
/// <summary>
/// Equiavlent to ||
/// </summary>
Or
Or,

/// <summary>
/// Not should be equivalent to &amp;&amp; but operation should be use Operation.NotEquals
/// </summary>
Not
}
}
33 changes: 33 additions & 0 deletions DynamicExpressionBuilder/Helpers/ExpressionBuilderHelpers.cs
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 };

}
}
}

0 comments on commit 37fe67b

Please sign in to comment.