Exemple #1
0
        private static void Qxx(ModelConfigurationNode destTree, List <KeyValuePair <Expression, Expression> > conditionalSetters, MutatorConfiguration mutatedMutator, CompositionPerformer performer, Expression resolvedKey)
        {
            var        unconditionalSetter = conditionalSetters.SingleOrDefault(pair => pair.Value == null);
            Expression invertedCondition   = null;

            foreach (var setter in conditionalSetters)
            {
                var mutatedPath = setter.Key;
                var condition   = setter.Value;
                if (condition == null)
                {
                    continue;
                }
                Expression currentInvertedCondition = Expression.Not(condition);
                invertedCondition = invertedCondition == null ? currentInvertedCondition : Expression.AndAlso(invertedCondition, currentInvertedCondition);
                var primaryDependencies = Expression.Lambda(mutatedPath, mutatedPath.ExtractParameters()).ExtractPrimaryDependencies().Select(lambda => lambda.Body);
                var commonPath          = primaryDependencies.FindLCP();
                var destNode            = commonPath == null ? destTree : destTree.Traverse(commonPath, true);
                destNode.mutators.Add(PurgeFilters(mutatedPath, mutatedMutator.If(Expression.Lambda(condition, condition.ExtractParameters()))));
            }

            {
                var mutatedPath         = unconditionalSetter.Key ?? performer.Perform(resolvedKey);
                var primaryDependencies = Expression.Lambda(mutatedPath, mutatedPath.ExtractParameters()).ExtractPrimaryDependencies().Select(lambda => lambda.Body);
                var commonPath          = primaryDependencies.FindLCP();
                var destNode            = commonPath == null ? destTree : destTree.Traverse(commonPath, true);
                destNode.mutators.Add(PurgeFilters(mutatedPath, invertedCondition == null ? mutatedMutator : mutatedMutator.If(Expression.Lambda(invertedCondition, invertedCondition.ExtractParameters()))));
            }
        }
        public static void AddMutatorSmart(this ModelConfigurationNode node, LambdaExpression path, MutatorConfiguration mutator, ConfiguratorReporter reporter = null)
        {
            path = (LambdaExpression)path.Simplify();
            var simplifiedPath = PathSimplifier.SimplifyPath(path, out var filter);

            mutator = mutator.ResolveAliases(ExpressionAliaser.CreateAliasesResolver(simplifiedPath.Body, path.Body));
            var mutatorToAdd = filter == null ? mutator : mutator.If(filter);

            reporter?.Report(simplifiedPath, path, mutatorToAdd);
            node.Traverse(simplifiedPath.Body, true).AddMutator(path.Body, mutatorToAdd);
        }