public string Calcul <T>(T data, LambdaExpression query, string format)
        {
            string reportValue;

            if (HasIssue(data, query, out reportValue))
            {
                return(reportValue);
            }

            // executes the aggregates
            query = (LambdaExpression)ExpressionPreProcessor.PreProcessor(data, query);

            // checks the rules against the results of the aggregates
            if (HasIssue(data, query, out reportValue))
            {
                return(reportValue);
            }

            Delegate lambda = query.Compile();
            decimal? result = (decimal?)lambda.DynamicInvoke(data);

            return(result != null
                    ? result.Value.ToString(format)
                    : TypeDonnee.Manquante.ReportValue);
        }
        public string Calcul <T>(T data, LambdaExpression query, string format)
        {
            query = (LambdaExpression)ExpressionPreProcessor.PreProcessor(data, query);

            var rulesCheckerResult = RulesChecker.Check(data, query);

            if (rulesCheckerResult.HasManquante)
            {
                return(TypeDonnee.Manquante.ReportValue);
            }

            if (rulesCheckerResult.HasDivisionParZero)
            {
                return(TypeDonnee.DivisionParZero.ReportValue);
            }

            if (rulesCheckerResult.HasNonDiffusable)
            {
                return(TypeDonnee.NonDiffusable.ReportValue);
            }

            if (rulesCheckerResult.HasConfidentielle)
            {
                return(TypeDonnee.Confidentielle.ReportValue);
            }

            Delegate lambda = query.Compile();
            decimal? result = (decimal?)lambda.DynamicInvoke(data);

            return(result != null
                    ? result.Value.ToString(format)
                    : TypeDonnee.Manquante.ReportValue);
        }
        public static Expression PreProcessor(object source, Expression expression)
        {
            if (!IsValidSource(source))
            {
                return(expression);
            }

            var visitor = new ExpressionPreProcessor(source);

            return(visitor.Visit(expression));
        }