Skip to content

Commit

Permalink
some code comments added
Browse files Browse the repository at this point in the history
  • Loading branch information
VahidFarahmandian committed Jan 22, 2023
1 parent 65b3ab3 commit 1064f28
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions Jinget.Core/Utilities/Expressions/ExpressionUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,31 +159,48 @@ public static Expression<Func<T, T>> CreateMemberInitExpression<T>(string parame
return Expression.Lambda<Func<T, T>>(memberinit, paramExpression);
}

public static Expression<Func<T, bool>> ConstructBinaryExpression<T>(object? json, bool treatNullAsTrueCondition = true)
/// <summary>
/// Construct a boolean expression based on a json input
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="json">a key/value structured json string/object, where keys are types property and values are their value</param>
/// <param name="treatNullOrEmptyAsTrueCondition">When <paramref name="json"/> is null or empty, then a default condition will be returned.
/// if this parameter's value is set to true the a default true condition will be returned otherwise a defaule false condition will be returned</param>
/// <returns></returns>
public static Expression<Func<T, bool>> ConstructBinaryExpression<T>(object? json, bool treatNullOrEmptyAsTrueCondition = true)
{
if (json is null)
{
return treatNullAsTrueCondition ? BooleanUtility.TrueCondition<T>() : BooleanUtility.FalseCondition<T>();
return treatNullOrEmptyAsTrueCondition ? BooleanUtility.TrueCondition<T>() : BooleanUtility.FalseCondition<T>();
}
else
return ConstructBinaryExpression<T>(json.ToString(), treatNullAsTrueCondition);
return ConstructBinaryExpression<T>(json.ToString(), treatNullOrEmptyAsTrueCondition);
}
public static Expression<Func<T, bool>> ConstructBinaryExpression<T>(string json, bool treatNullAsTrueCondition = true)

/// <summary>
/// Construct a boolean expression based on a json input
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="json">a key/value structured json string/object, where keys are types property and values are their value</param>
/// <param name="treatNullOrEmptyAsTrueCondition">When <paramref name="json"/> is null or empty, then a default condition will be returned.
/// if this parameters value is set to true the a default true condition will be returned otherwise a defaule false condition will be returned</param>
/// <returns></returns>
public static Expression<Func<T, bool>> ConstructBinaryExpression<T>(string json, bool treatNullOrEmptyAsTrueCondition = true)
{
if (string.IsNullOrWhiteSpace(json.ToString()))
{
return treatNullAsTrueCondition ? BooleanUtility.TrueCondition<T>() : BooleanUtility.FalseCondition<T>();
return treatNullOrEmptyAsTrueCondition ? BooleanUtility.TrueCondition<T>() : BooleanUtility.FalseCondition<T>();
}

var filters = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);

var type = typeof(T);
var exprVar = Expression.Parameter(type, "x");

//if there is no filter specified, then return a true condition
//if there is no filter specified, then return the default true/false condition
if (filters == null || !filters.Any())
{
return BooleanUtility.TrueCondition<T>();
return treatNullOrEmptyAsTrueCondition ? BooleanUtility.TrueCondition<T>() : BooleanUtility.FalseCondition<T>();
}

//construct queries
Expand Down

0 comments on commit 1064f28

Please sign in to comment.