Beispiel #1
0
        public override INotifyExpression <T> ApplyParameters(IDictionary <string, object> parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var applyParameters = new RepositoryChangeApplyParametersVisitor(parameters);
            var newBody         = applyParameters.Visit(Body);

            var changeInfos = ChangeInfos;

            if (applyParameters.Recorders != null)
            {
                if (changeInfos == null)
                {
                    changeInfos = applyParameters.Recorders;
                }
                else
                {
                    changeInfos = new List <IChangeInfo>(changeInfos);
                    changeInfos.AddRange(applyParameters.Recorders);
                }
            }

            if (parameters.Count == Parameters.Count)
            {
                var lambda = Expression.Lambda <Func <T> >(newBody);
                var setter = SetExpressionRewriter.CreateSetter(lambda);
                if (setter == null)
                {
                    throw new InvalidOperationException(string.Format("The lambda expression {0} could not be reversed.", newBody));
                }
                if (changeInfos == null)
                {
                    return(new RepositoryAffectedReversableNotifyValue <T>(Repository, lambda.Compile(), setter.Compile()));
                }
                else
                {
                    return(new RepositoryAffectedDependentReversableNotofyValue <T>(Repository, lambda.Compile(), setter.Compile(), changeInfos));
                }
            }
            else
            {
                return(new RepositoryAffectedReversableNotifyFunc <T>(Repository, newBody, Parameters.Where(p => !parameters.ContainsKey(p.Name)), changeInfos));
            }
        }
Beispiel #2
0
        public virtual INotifyExpression <T> ApplyParameters(IDictionary <string, object> parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var applyParameters = new RepositoryChangeApplyParametersVisitor(parameters);
            var newBody         = applyParameters.Visit(Body);

            var changeInfos = ChangeInfos;

            if (applyParameters.Recorders != null)
            {
                if (changeInfos == null)
                {
                    changeInfos = applyParameters.Recorders;
                }
                else
                {
                    changeInfos = new List <IChangeInfo>(changeInfos);
                    changeInfos.AddRange(applyParameters.Recorders);
                }
            }

            if (parameters.Count == Parameters.Count)
            {
                var lambda = Expression.Lambda <Func <T> >(newBody);
                if (changeInfos == null)
                {
                    return(new RepositoryAffectedNotifyValue <T>(Repository, lambda.Compile()));
                }
                else
                {
                    return(new RepositoryAffectedDependentNotifyValue <T>(Repository, lambda.Compile(), changeInfos));
                }
            }
            else
            {
                return(new RepositoryAffectedNotifyFunc <T>(Repository, newBody, Parameters.Where(p => !parameters.ContainsKey(p.Name)), changeInfos));
            }
        }