private Expression <Func <TEntity, bool> > BuildTypedLambdaIncludingPrincipals <TEntity>(IClearanceSource clearanceSource, Expression entitySourceExpression = null) { Expression body = this.BuildUntypedFilterExpressionIncludingPrincipals(clearanceSource); if (body == null) { body = BinaryExpression.Constant(true); } return(Expression.Lambda <Func <TEntity, bool> >(body, _EntityParameter)); }
private Expression BuildAcValueOrExpressionForDimensionClearanceValues(MemberExpression propExpr, Type propertyType, string[] dimensionClearanceValues) { if (!dimensionClearanceValues.Any()) { return(BinaryExpression.Constant(false)); } Expression grandExpr = null; Expression denyExpr = null; foreach (string dimensionClearanceValue in dimensionClearanceValues) { string value = dimensionClearanceValue.Trim(); Expression constClearance = this.BuildConstValueExpressionFromString(propertyType, value); if (value.StartsWith("!")) { value = value.Substring(1); if (value == "*") { return(BinaryExpression.Constant(false)); } if (denyExpr == null) { denyExpr = Expression.Equal(propExpr, constClearance); } else { denyExpr = Expression.OrElse(denyExpr, Expression.Equal(propExpr, constClearance)); } } else { if (value == "*") { return(BinaryExpression.Constant(true)); } if (grandExpr == null) { grandExpr = Expression.Equal(propExpr, constClearance); } else { grandExpr = Expression.OrElse(grandExpr, Expression.Equal(propExpr, constClearance)); } } } if (denyExpr == null) { if (grandExpr == null) { return(BinaryExpression.Constant(false)); } else { return(grandExpr); } } else { Expression notDeniedExpr = Expression.Not(denyExpr); if (grandExpr == null) { return(notDeniedExpr); } else { return(Expression.AndAlso(grandExpr, notDeniedExpr)); } } }