Example #1
0
        public Expression Mutate(IList <Expression> operands)
        {
            var           bindings     = new List <MemberBinding>();
            int           operandIndex = MemberInitExpression.NewExpression.Arguments.Count();
            NewExpression newNewExpression;

            if (MemberInitExpression.NewExpression.Constructor != null)
            {
                newNewExpression = Expression.New(MemberInitExpression.NewExpression.Constructor,
                                                  operands.Take(operandIndex));
            }
            else
            {
                newNewExpression = Expression.New(MemberInitExpression.NewExpression.Type);
            }
            foreach (var memberBinding in MemberInitExpression.Bindings)
            {
                var memberBindingMutator = MemberBindingMutatorFactory.GetMutator(memberBinding);
                int operandsCount        = memberBindingMutator.Operands.Count();
                var subOperands          = operands.Skip(operandIndex).Take(operandsCount).ToList();
                bindings.Add(memberBindingMutator.Mutate(subOperands));
                operandIndex += operandsCount;
            }
            return(Expression.MemberInit(newNewExpression, bindings));
        }
        public MemberBinding Mutate(IList <Expression> operands)
        {
            var bindings      = new List <MemberBinding>();
            int operandsIndex = 0;

            // same thing here. The difficulty is that we have to split out operands
            foreach (var memberBinding in MemberMemberBinding.Bindings)
            {
                int operandsCount = MemberBindingMutatorFactory.GetMutator(memberBinding).Operands.Count();
                var subOperands   = operands.Skip(operandsIndex).Take(operandsCount).ToList();
                bindings.Add(MemberBindingMutatorFactory.GetMutator(memberBinding).Mutate(subOperands));
                operandsIndex += operandsCount;
            }
            return(Expression.MemberBind(MemberMemberBinding.Member, bindings));
        }