public ApplyUnorderedCollectionWithIdPatch(MergerImplementation mergerImplementation)
        {
            this.aMergerImplementation = mergerImplementation;

            this.aIdProperty = GeneralRulesHelper <TItemType> .GetIdProperty(mergerImplementation);

            this.aApplyItemDiff = null;
        }
示例#2
0
        public TType Apply(TType source, IDiff <TType> patch)
        {
            if (this.aConvertor == null)
            {
                this.aConvertor     = this.CompileConvertor();
                this.aApplyItemDiff = this.aMergerImplementation.Partial.Algorithms.GetApplyPatchAlgorithm <TItemType>();
            }

            return(this.ApplyInternal((IEnumerable <KeyValuePair <TKeyType, TItemType> >)source, patch));
        }
        public TType Apply(TType source, IDiff <TType> patch)
        {
            if (this.aIdAccessor == null)
            {
                this.aIdAccessor    = IdHelpers.CreateIdAccessor <TItemType, TIdType>(this.aIdProperty);
                this.aApplyItemDiff = this.aMergerImplementation.Partial.Algorithms.GetApplyPatchAlgorithm <TItemType>();
                this.aConvertor     = this.CompileConvertor();
            }

            return(this.ApplyInternal((IEnumerable <TItemType>)source, patch));
        }
示例#4
0
        private SwitchCase EvaluateProperty(ParameterExpression ret, ParameterExpression orig, Property property, ParameterExpression item)
        {
            IApplyPatchAlgorithm algorithm = this.aMergerImplementation.Partial.Algorithms.GetApplyPatchAlgorithm(property.Type);

            Expression applicator = Expression.IfThenElse(
                Expression.TypeIs(item, typeof(IDiffItemReplaced)),
                Expression.Assign(
                    Expression.Property(ret, property.ReflectionPropertyInfo),
                    Expression.Property(
                        Expression.Convert(item, typeof(IDiffItemReplaced <>).MakeGenericType(property.Type)),
                        DiffItemsMembers.ReplacedNewValue(property.Type)
                        )
                    ),
                Expression.Throw(
                    Expression.New(
                        typeof(Exception)                         // TODO: Better exception
                        )
                    )
                );

            if (algorithm != null)
            {
                applicator = Expression.IfThenElse(
                    Expression.TypeIs(item, typeof(IDiffItemChanged)),
                    Expression.Assign(
                        Expression.Property(ret, property.ReflectionPropertyInfo),
                        Expression.Call(
                            Expression.Constant(algorithm),
                            ApplyPatchAlgorithmMembers.Apply(property.Type),
                            Expression.Property(orig, property.ReflectionPropertyInfo),
                            Expression.Property(
                                Expression.Convert(item, typeof(IDiffItemChanged <>).MakeGenericType(property.Type)),
                                DiffItemsMembers.ChangedDiff(property.Type)
                                )
                            )
                        ),
                    applicator
                    );
            }

            return(Expression.SwitchCase(applicator, Expression.Constant(property.UniqueID)));
        }
        public TType ApplyPatch <TType>(TType @object, IDiff <TType> patch)
        {
            IApplyPatchAlgorithm <TType> algorithm = this.Algorithms.GetApplyPatchAlgorithm <TType>();

            return(algorithm.Apply(@object, patch));
        }
示例#6
0
 public ApplyKeyValueCollectionPatch(MergerImplementation mergerImplementation)
 {
     this.aMergerImplementation = mergerImplementation;
     this.aConvertor            = null;
     this.aApplyItemDiff        = null;
 }