Exemple #1
0
        public static void AddMutatorSmart(this ModelConfigurationNode node, LambdaExpression path, MutatorConfiguration mutator)
        {
            path = (LambdaExpression)path.Simplify();
            LambdaExpression filter;
            var simplifiedPath = PathSimplifier.SimplifyPath(path, out filter);

            mutator = mutator.ResolveAliases(ExpressionAliaser.CreateAliasesResolver(simplifiedPath.Body, path.Body));
            node.Traverse(simplifiedPath.Body, true).AddMutator(path.Body, filter == null ? mutator : mutator.If(filter));
        }
Exemple #2
0
        private static KeyValuePair <Expression, MutatorConfiguration> PurgeFilters(Expression path, MutatorConfiguration mutator)
        {
            var filters     = new List <LambdaExpression>();
            var cleanedPath = path.CleanFilters(filters);

            if (filters.Any(filter => filter != null))
            {
                var shards                 = path.SmashToSmithereens();
                var cleanedShards          = cleanedPath.SmashToSmithereens();
                var aliases                = new List <KeyValuePair <Expression, Expression> >();
                var i                      = 0;
                var j                      = 0;
                LambdaExpression condition = null;
                foreach (var filter in filters)
                {
                    while (!(shards[i].NodeType == ExpressionType.Call && (((MethodCallExpression)shards[i]).Method.IsCurrentMethod() || ((MethodCallExpression)shards[i]).Method.IsEachMethod())))
                    {
                        ++i;
                    }
                    while (!(cleanedShards[j].NodeType == ExpressionType.Call && (((MethodCallExpression)cleanedShards[j]).Method.IsCurrentMethod() || ((MethodCallExpression)cleanedShards[j]).Method.IsEachMethod())))
                    {
                        ++j;
                    }
                    if (filter == null)
                    {
                        continue;
                    }
                    aliases.Add(new KeyValuePair <Expression, Expression>(cleanedShards[j], shards[i]));
                    condition = condition == null ? filter : condition.AndAlso(filter, false);
                    ++i;
                    ++j;
                }

                mutator = mutator.ResolveAliases(new LambdaAliasesResolver(aliases)).If(condition);
            }

            return(new KeyValuePair <Expression, MutatorConfiguration>(cleanedPath, mutator));
        }