Example #1
0
        /// <inheritdoc/>
        public void Copy(
            T source,
            T target,
            ICopyCallContext copyCallContext)
        {
            source.NotNull(nameof(source));
            target.NotNull(nameof(target));
            copyCallContext.NotNull(nameof(copyCallContext));

            var sourceChild = this.sourceFunc.Invoke(source);

            // if the source is null, set the target also to null and exit copy process step.
            if (sourceChild == null)
            {
                target.SetPropertyValue(this.targetExpression, null);
                return;
            }

            var sourceConcrete = sourceChild as TConcreteChild;

            sourceConcrete.NotNull(nameof(sourceConcrete));

            var copy = this.createCopyHelper.CreateTarget(
                sourceConcrete,
                target,
                copyCallContext);

            target.SetPropertyValue(this.targetExpression, copy);
        }
 /// <inheritdoc/>
 public void Copy(T source, T target, ICopyCallContext copyCallContext)
 {
     foreach (var registeredStrategy in this.registeredStrategies)
     {
         registeredStrategy.Copy(source, target, copyCallContext);
     }
 }
        /// <inheritdoc/>
        public void Copy(T source, T target, ICopyCallContext copyCallContext)
        {
            copyCallContext.NotNull(nameof(copyCallContext));
            this.additionalProcessings.NotNull(nameof(this.additionalProcessings));

            copyCallContext.AdditionalProcessings.AddRangeToMe(this.additionalProcessings);
        }
        /// <inheritdoc/>
        public TChild CreateTarget(
            TConcreteChild source,
            TParent reverseRelation,
            ICopyCallContext copyCallContext)
        {
            source.NotNull(nameof(source));
            reverseRelation.NotNull(nameof(reverseRelation));
            copyCallContext.NotNull(nameof(copyCallContext));

            if (copyCallContext.AdditionalProcessings.OfType <IGenericContinueCopyInterception <TChild> >().Any(continueCopyInterception => !continueCopyInterception.ShallCopy(source)))
            {
                return(null);
            }

            var target = this.instanceCreator.Create();

            // Back reference should be set before copy method because copy could potentially use this back reference.
            target.SetPropertyValue(this.reverseRelationExpr, reverseRelation);
            this.copy.Copy(source, target, copyCallContext);

            // Make sure that copy did not overwrite the target's reverse relation therefore back reference is set here
            // for a second time.
            target.SetPropertyValue(this.reverseRelationExpr, reverseRelation);
            return(target);
        }
Example #5
0
            public void Copy(IChildTestClass source, IChildTestClass target, ICopyCallContext copyCallContext)
            {
                source.Should().NotBeNull();
                target.Should().NotBeNull();
                copyCallContext.Should().NotBeNull();

                target.TestValue = source.TestValue * 2;
            }
        /// <inheritdoc/>
        public void Copy(T source, T target, ICopyCallContext copyCallContext)
        {
            var value = this.func.Invoke(source);

            var targetProperty = target.GetType().GetProperty(this.propertyName, BindingFlags.Public | BindingFlags.Instance);

            if (targetProperty != null)
            {
                targetProperty.SetValue(target, value, null);
            }
        }
        /// <inheritdoc/>
        public virtual void Copy(
            TBase source,
            TBase target,
            ICopyCallContext copyCallContext)
        {
            var sourceCastConcrete = source.IsOfType <TDerived>(nameof(source));
            var targetCastConcrete = target.IsOfType <TDerived>(nameof(target));

            copyCallContext.NotNull(nameof(copyCallContext));

            this.copier.Copy(sourceCastConcrete, targetCastConcrete, copyCallContext);
        }
        /// <inheritdoc/>
        public void Copy(
            T source,
            T target,
            ICopyCallContext copyCallContext)
        {
            copyCallContext.NotNull(nameof(copyCallContext));

            var crossReferenceHandler =
                new CopyCrossReferencedCounterPartDeterminationHelper <TCrossReferencedModel, TReferencingModel>(
                    this.referencingProperyExpression);

            crossReferenceHandler.FillAdditionalProcessings(copyCallContext.AdditionalProcessings);
        }
Example #9
0
        /// <inheritdoc/>
        public void Copy(
            T source,
            T target,
            ICopyCallContext copyCallContext)
        {
            source.NotNull(nameof(source));
            target.NotNull(nameof(target));
            copyCallContext.NotNull(nameof(copyCallContext));

            this.operations.Copy(source, target, copyCallContext);

            this.copyHelper.DoCopyPostProcessing(source, target, copyCallContext.AdditionalProcessings);
        }
Example #10
0
        /// <summary>
        /// <see cref="ICopyOperation{T}"/>.
        /// </summary>
        public void Copy(
            T source,
            T target,
            ICopyCallContext copyCallContext)
        {
            var newKidsList = new List <TChild>();

            foreach (var child in this.sourceFunc.Invoke(source))
            {
                var strategy  = this.strategyProvider.GetStrategy(child);
                var childCopy = strategy.Create();
                strategy.Copy(child, childCopy, copyCallContext);
                childCopy.SetPropertyValue(this.reverseRelationExpression, target);
                newKidsList.Add(childCopy);
            }
        }
        /// <summary>
        /// <see cref="ICopyOperationCreateToManyWithGenericStrategy{T,TStrategy,TChildType}"/>.
        /// </summary>
        public void Copy(
            T source,
            T target,
            ICopyCallContext copyCallContext)
        {
            var newKidsList = new List <TChildType>();

            foreach (var child in this.sourceFunc.Invoke(source))
            {
                var strategy  = this.strategyProvider.GetStrategy(child);
                var childCopy = this.createTargetChildFunc.Invoke(strategy);
                strategy.Copy(child, childCopy, copyCallContext);
                newKidsList.Add(childCopy);
            }

            target.AddRangeFilterNullValues(this.targetExpression, newKidsList);
        }
Example #12
0
        /// <summary>
        /// <see cref="ICopyOperation{T}"/>.
        /// </summary>
        public void Copy(
            T source,
            T target,
            ICopyCallContext copyCallContext)
        {
            var sourceChild = this.sourceFunc.Invoke(source);

            // if the source is null, set the target also to null and exit copy process step.
            if (sourceChild == null)
            {
                target.SetPropertyValue(this.targetExpression, null);
                return;
            }

            var strategy = this.strategyProvider.GetStrategy(sourceChild);

            var copy = strategy.Create();

            strategy.Copy(sourceChild, copy, copyCallContext);
            copy.SetPropertyValue(this.reverseRelationExpression, target);

            target.SetPropertyValue(this.targetExpression, copy);
        }
        /// <inheritdoc/>
        public void Copy(TParent source, TParent target, ICopyCallContext copyCallContext)
        {
            source.NotNull(nameof(source));
            target.NotNull(nameof(target));
            copyCallContext.NotNull(nameof(copyCallContext));

            var sourceValues = this.sourceFunc.Invoke(source)?.ToList();

            sourceValues.NotNull(nameof(sourceValues));

            // ReSharper disable once AssignNullToNotNullAttribute -> .NotNull is called before!
            var copies = sourceValues.Select(sourceValue => this.createCopyHelper.CreateTarget(
                                                 sourceValue as TConcreteChild,
                                                 target,
                                                 copyCallContext)).ToList();

            this.maybeTargetExpression.Do(targetExpression =>
            {
                target.AddRangeFilterNullValues(
                    targetExpression,
                    copies);
            });
        }
        /// <summary>
        /// <see cref="ICopyOperation{T}.Copy"/>.
        /// </summary>
        public void Copy(T source, T target, ICopyCallContext copyCallContext)
        {
            var value = this.attrValueFunc.Invoke(this.attributeValueFactory);

            target.SetPropertyValue(this.targetExpression, value);
        }
Example #15
0
 /// <inheritdoc/>
 public void Copy(T source, T target, ICopyCallContext copyCallContext)
 {
     target.SetPropertyValue(this.targetExpression, this.valueFunc.Invoke());
 }
Example #16
0
 /// <inheritdoc/>
 public void Copy(T source, T target, ICopyCallContext copyCallContext)
 {
     this.copier.Copy(source, target, copyCallContext);
 }