Ejemplo n.º 1
0
        public static Expression IsAllowedExpression(Expression entity, TypeAllowedBasic requested, bool inUserInterface)
        {
            Type type = entity.Type;

            TypeAllowedAndConditions tac = GetAllowed(type);

            Expression baseValue = Expression.Constant(tac.FallbackOrNone.Get(inUserInterface) >= requested);

            var expression = tac.Conditions.Aggregate(baseValue, (acum, tacRule) =>
            {
                var lambda = TypeConditionLogic.GetCondition(type, tacRule.TypeCondition);

                var exp = (Expression)Expression.Invoke(lambda, entity);

                if (tacRule.Allowed.Get(inUserInterface) >= requested)
                {
                    return(Expression.Or(exp, acum));
                }
                else
                {
                    return(Expression.And(Expression.Not(exp), acum));
                }
            });

            var cleaned = DbQueryProvider.Clean(expression, false, null) !;

            var orsSimplified = AndOrSimplifierVisitor.SimplifyOrs(cleaned);

            return(orsSimplified);
        }
        internal static Expression IsAllowedExpressionDebug(Expression entity, TypeAllowedBasic requested, bool inUserInterface)
        {
            Type type = entity.Type;

            TypeAllowedAndConditions tac = GetAllowed(type);

            Expression baseValue = Expression.Constant(tac.FallbackOrNone.Get(inUserInterface) >= requested);

            var list = (from line in tac.Conditions
                        select Expression.New(ciGroupDebugData, Expression.Constant(line.TypeCondition, typeof(TypeConditionSymbol)),
                                              Expression.Invoke(TypeConditionLogic.GetCondition(type, line.TypeCondition), entity),
                                              Expression.Constant(line.Allowed))).ToArray();

            Expression newList = Expression.ListInit(Expression.New(typeof(List <ConditionDebugData>)), list);

            Expression liteEntity = Expression.Call(null, miToLite.MakeGenericMethod(entity.Type), entity);

            return(Expression.New(ciDebugData, liteEntity,
                                  Expression.Constant(requested),
                                  Expression.Constant(inUserInterface),
                                  Expression.Constant(tac.Fallback),
                                  newList));
        }