public object Replicate(object source, IReplicationContext context)
 {
     Guard.AgainstViolation(source.GetType().GetElementType() == elementType,
         "This replicator can copy only arrays of elements of type {0}, but {1} received",
         elementType, source.GetType().GetElementType());
     var resultingArray = source.As<Array>().Clone().As<Array>();
     for (int i = resultingArray.Length - 1; i >= 0; i--) {
         object sourceElement = getElement(resultingArray, i);
         object resultingElement = context.Replicate(sourceElement);
         setElement(resultingArray, i, resultingElement);
     }
     return resultingArray;
 }
Exemple #2
0
        public object Replicate(object source, IReplicationContext context)
        {
            Guard.AgainstViolation(source.GetType().GetElementType() == elementType,
                                   "This replicator can copy only arrays of elements of type {0}, but {1} received",
                                   elementType, source.GetType().GetElementType());
            var resultingArray = source.As <Array>().Clone().As <Array>();

            for (int i = resultingArray.Length - 1; i >= 0; i--)
            {
                object sourceElement    = getElement(resultingArray, i);
                object resultingElement = context.Replicate(sourceElement);
                setElement(resultingArray, i, resultingElement);
            }
            return(resultingArray);
        }
        public object Replicate(object source, IReplicationContext context)
        {
            Guard.AgainstViolation(source.GetType() == entityType,
                "This replicator can copy only entities of type {0}, but {1} received",
                entityType, source.GetType());

            object result = FormatterServices.GetUninitializedObject(entityType);
            foreach (var memberReplicationInfo in memberDescriptions) {
                object memberValue = memberReplicationInfo.GetMember(source);
                object replicatedValue = memberReplicationInfo.Behavior == ReplicationBehavior.DeepCopy
                    ? context.Replicate(memberValue)
                    : memberValue;
                result = memberReplicationInfo.SetMember(result, replicatedValue);
            }
            return result;
        }
Exemple #4
0
        public object Replicate(object source, IReplicationContext context)
        {
            Guard.AgainstViolation(source.GetType() == entityType,
                                   "This replicator can copy only entities of type {0}, but {1} received",
                                   entityType, source.GetType());

            object result = FormatterServices.GetUninitializedObject(entityType);

            foreach (var memberReplicationInfo in memberDescriptions)
            {
                object memberValue     = memberReplicationInfo.GetMember(source);
                object replicatedValue = memberReplicationInfo.Behavior == ReplicationBehavior.DeepCopy
                    ? context.Replicate(memberValue)
                    : memberValue;
                result = memberReplicationInfo.SetMember(result, replicatedValue);
            }
            return(result);
        }