public MethodInfos()
 {
     GetUninitializedObject = GetFuncCall(() => FormatterServices.GetUninitializedObject(typeof(int)));
     GetTypeFromHandle      = GetFuncCall(() => Type.GetTypeFromHandle(typeof(Type).TypeHandle));
     CopyInner    = GetFuncCall(() => DeepCopier.Copy(default(object), default)).GetGenericMethodDefinition();
     TryGetCopy   = typeof(DeepCopyContext).GetMethod("TryGetCopy");
     RecordObject = GetActionCall((DeepCopyContext ctx) => ctx.RecordCopy(default, default));
Example #2
0
        public void CanCopyIntegers()
        {
            var original = 123;
            var result   = DeepCopier.Copy(original);

            Assert.Equal(original, result);
        }
Example #3
0
 public void DeepCopy()
 {
     for (var i = 0; i < Count; i++)
     {
         DeepCopier.Copy(Price);
     }
 }
Example #4
0
        public void ImmutableWrapperTypesAreNotCopied()
        {
            var original = Immutable.Create(new object[] { 123, "hello!" });
            var result   = DeepCopier.Copy(original);

            Assert.Same(original.Value, result.Value);
        }
        public static Dictionary <string, object> Export(DeepCopier copier)
        {
            var values = RequestContext.CallContextData.Value;

            if (RequestContext.PropagateActivityId)
            {
                var activityIdOverride = Trace.CorrelationManager.ActivityId;
                if (activityIdOverride != Guid.Empty)
                {
                    object existingActivityId;
                    if (values == null ||
                        !values.TryGetValue(RequestContext.E2_E_TRACING_ACTIVITY_ID_HEADER, out existingActivityId) ||
                        activityIdOverride != (Guid)existingActivityId)
                    {
                        // Create new copy before mutating data
                        values = values == null ? new Dictionary <string, object>() : new Dictionary <string, object>(values);
                        values[RequestContext.E2_E_TRACING_ACTIVITY_ID_HEADER] = activityIdOverride;
                    }
                }
            }

            return((values != null && values.Count > 0)
                ? copier.Copy(values)
                : null);
        }
Example #6
0
        public void CanCopyStrings()
        {
            var original = "hello!";
            var result   = DeepCopier.Copy(original);

            Assert.Same(original, result);
        }
Example #7
0
        public async Task SaveSnapshotAsync(IAggregateRoot aggregateRoot, Type aggregateRootType, int publishedVersion)
        {
            if (aggregateRoot == null)
            {
                throw new ArgumentNullException(nameof(aggregateRoot));
            }

            if (publishedVersion % _aggregateSnapshotConfiguration.VersionInterval != 0)
            {
                return;
            }

            var copiedAggregateRoot   = DeepCopier.Copy(aggregateRoot);
            var aggregateRootJson     = _aggregateSnapshotSerializer.Serialize(copiedAggregateRoot);
            var aggregateRootTypeName = _typeNameProvider.GetTypeName(aggregateRootType);
            var snapshot = new Snapshot()
            {
                CreationTime          = DateTime.UtcNow,
                ModificationTime      = DateTime.UtcNow,
                AggregateRootId       = copiedAggregateRoot.UniqueId,
                AggregateRootTypeName = aggregateRootTypeName,
                Version           = copiedAggregateRoot.Version,
                SerializedPayload = aggregateRootJson,
            };
            var sql = string.Format(InsertOrUpdateSnapshotSql, _snapshotRepository.GetTableName(snapshot.AggregateRootId));

            using (var connection = _snapshotRepository.GetConnection())
            {
                await connection.ExecuteAsync(sql, snapshot);
            }
        }
 public static T DeepCopy <T>(T value, DeepCopyOptions options = DeepCopyOptions.DeepCopier)
 {
     return(options switch
     {
         DeepCopyOptions.DeepCopier => DeepCopier.Copy(value),
         DeepCopyOptions.ExpressionCopier => ExpressionCopier <T> .Copy(value),
         _ => ExpressionCopier <T> .Copy(value)
     });
Example #9
0
        public void CanCopyArraysTwoDimensional()
        {
            var original = new object[][] { new object[] { 123, "hello!" }, new object[] { 123, "hello!" } };
            var result   = DeepCopier.Copy(original);

            Assert.Equal(original, result);
            Assert.NotSame(original, result);
        }
Example #10
0
        public void CanCopyPrimitiveArrays()
        {
            var original = new int[] { 1, 2, 3 };
            var result   = DeepCopier.Copy(original);

            Assert.Equal(original, result);
            Assert.NotSame(original, result);
        }
Example #11
0
        public void CanCopyMutableKeyValuePair()
        {
            var original = new KeyValuePair <string, Poco>("Hello", new Poco());
            var result   = DeepCopier.Copy(original);

            Assert.Same(original.Key, result.Key);
            Assert.NotSame(original.Value, result.Value);
        }
Example #12
0
        public void CanCopyMutableValueTupleRest()
        {
            var original = new ValueTuple <int, string, double, int, string, double, int, ValueTuple <Poco> >(5, "hello",
                                                                                                              1d, 2, "world", 3d, 7,
                                                                                                              new ValueTuple <Poco>(new Poco()));
            var result = DeepCopier.Copy(original);

            Assert.NotEqual(original.Rest, result.Rest);
        }
Example #13
0
        public INode GetTraversedTree(List <bool> answers)
        {
            //Deep Clone Original Data Source.
            INode node = DeepCopier.Copy(_dataSource.DecisionTree);

            //node = node.DeepClone();
            GetTraversedTree(answers.ToList(), ref node);
            return(node);
        }
        internal static object OrleansSerializationLoop(Serializer serializer, DeepCopier copier, object input, bool includeWire = true)
        {
            var copy = copier.Copy(input);

            if (includeWire)
            {
                copy = serializer.RoundTripSerializationForTesting(copy);
            }
            return(copy);
        }
Example #15
0
        public void RegressionTest_20()
        {
            var original = new Dictionary <int, Component>()
            {
                { 1, new Component() },
            };
            var result = DeepCopier.Copy(original);

            GC.GetTotalMemory(true); // force full GC
        }
Example #16
0
        public void CanCopyArraysRank3()
        {
            var original = new object[, , ] {
                { { "Hello", 2, "World" }, { 300.0f, "World", 33 } }, { { 92, 5.0m, 135 }, { 30, true, 3 } }
            };
            var result = DeepCopier.Copy(original);

            Assert.Equal(original, result);
            Assert.NotSame(original, result);
        }
Example #17
0
        public void ImmutableTypesAreNotCopied()
        {
            var original = new ImmutablePoco {
                Reference = new object[] { 123, "hello!" }
            };
            var result = DeepCopier.Copy(original);

            Assert.Same(original.Reference, result.Reference);
            Assert.Same(original, result);
        }
Example #18
0
        public void CanCopyPrimitiveArraysRank3()
        {
            var original = new int[, , ] {
                { { 12, 2, 35 }, { 300, 78, 33 } }, { { 92, 42, 135 }, { 30, 7, 3 } }
            };
            var result = DeepCopier.Copy(original);

            Assert.Equal(original, result);
            Assert.NotSame(original, result);
        }
Example #19
0
        public void ReferencesInArraysArePreserved()
        {
            var poco     = new Poco();
            var original = new[] { poco, poco };

            var result = DeepCopier.Copy(original);

            Assert.NotSame(original, result);
            Assert.Same(result[0], result[1]);
        }
Example #20
0
        public void CanCopyInterfaceField()
        {
            PocoWithInterface original = new PocoWithInterface();

            original.Collection.Add("A");

            var result = DeepCopier.Copy(original);

            Assert.NotSame(original, result);
            Assert.NotSame(original.Collection, result.Collection);
        }
Example #21
0
        public void CanCopyCyclicObjectsWithBaseSibling()
        {
            var original = new CyclicPocoWithBaseSibling();

            original.BaseSibling = original;

            var result = DeepCopier.Copy(original);

            Assert.NotSame(original, result);
            Assert.Same(result, result.BaseSibling);
        }
Example #22
0
        public void CanCopyCyclicObjectsWithChildren()
        {
            var original = new CyclicPocoWithChildren();

            original.Children.Add(original);

            var result = DeepCopier.Copy(original);

            Assert.NotSame(original, result);
            Assert.Same(result, result.Children[0]);
        }
Example #23
0
        public void CanCopyCyclicObjects()
        {
            var original = new Poco();

            original.Reference = original;

            var result = DeepCopier.Copy(original);

            Assert.NotSame(original, result);
            Assert.Same(result, result.Reference);
        }
Example #24
0
        public void CanCopyBaseClassField()
        {
            PocoWithBaseClass original =
                new PocoWithBaseClass(new DerivedChildClass());


            var result = DeepCopier.Copy(original);

            Assert.NotSame(original, result);
            Assert.NotSame(original.Child, result.Child);
        }
Example #25
0
        public void ListOfSimpleClassDifferentInstances_DeepCopy()
        {
            var clone = DeepCopier.Copy(this._listOfSimpleClassDifferentInstances);

            Assert.NotSame(clone, this._listOfSimpleClassDifferentInstances);
            var firstInstance = clone[0];

            for (int i = 1; i < clone.Count; i++)
            {
                Assert.NotSame(firstInstance, clone[i]);
            }
        }
Example #26
0
        public void CanCopyPrivateReadonly()
        {
            var poco = new Poco();

            poco.Reference = poco;
            var original = new PocoWithPrivateReadonly(poco);

            var result = DeepCopier.Copy(original);

            Assert.NotSame(original, result);
            Assert.Same(result.GetReference(), ((Poco)result.GetReference()).Reference);
        }
Example #27
0
        public void CanCopyPrimitiveTwoDimensionalArraysShallow()
        {
            var original = new int[][]
            {
                new int[] { 1, 3, 5, 7, 9 },
                new int[] { 0, 2, 4, 6 },
                new int[] { 11, 22 }
            };
            var result = DeepCopier.Copy(original);

            Assert.Equal(original, result);
            Assert.NotSame(original, result);
        }
Example #28
0
        public async Task SaveSnapshotAsync(IAggregateRoot aggregateRoot, Type aggregateRootType, int publishedVersion)
        {
            if (aggregateRoot == null)
            {
                throw new ArgumentNullException(nameof(aggregateRoot));
            }

            if (publishedVersion % _aggregateSnapshotConfiguration.VersionInterval != 0)
            {
                return;
            }

            var copiedAggregateRoot   = DeepCopier.Copy(aggregateRoot);
            var aggregateRootJson     = _aggregateSnapshotSerializer.Serialize(copiedAggregateRoot);
            var aggregateRootTypeName = _typeNameProvider.GetTypeName(aggregateRootType);
            var snapshot = new Snapshot()
            {
                Id                    = ObjectId.GenerateNewId(),
                CreationTime          = DateTime.UtcNow,
                ModificationTime      = DateTime.UtcNow,
                AggregateRootId       = copiedAggregateRoot.UniqueId,
                AggregateRootTypeName = aggregateRootTypeName,
                Version               = copiedAggregateRoot.Version,
                Payload               = aggregateRootJson,
            };

            var filter = Builders <Snapshot>
                         .Filter
                         .Eq(s => s.AggregateRootId, snapshot.AggregateRootId);

            var update = Builders <Snapshot>
                         .Update
                         .Set(s => s.ModificationTime, snapshot.ModificationTime)
                         .Set(s => s.Version, snapshot.Version)
                         .Set(s => s.Payload, snapshot.Payload)
                         .SetOnInsert(s => s.Id, snapshot.Id)
                         .SetOnInsert(s => s.CreationTime, snapshot.CreationTime)
                         .SetOnInsert(s => s.AggregateRootId, snapshot.AggregateRootId)
                         .SetOnInsert(s => s.AggregateRootTypeName, snapshot.AggregateRootTypeName);

            await _snapshotCollection
            .GetCollection(copiedAggregateRoot.UniqueId)
            .UpdateOneAsync(filter, update, new UpdateOptions()
            {
                IsUpsert = true
            });
        }
Example #29
0
 public void CanCopyCollections()
 {
     {
         var original = new HashSet <int>(new[] { 123, 4, 5, 6 });
         var result   = DeepCopier.Copy(original);
         Assert.Equal(original, result);
         Assert.NotSame(original, result);
     }
     {
         var original = new Dictionary <int, int> {
             [1] = 1, [2] = 2
         };
         var result = DeepCopier.Copy(original);
         Assert.Equal(original, result);
         Assert.NotSame(original, result);
     }
 }
Example #30
0
        public void CanCopyPrimitiveThreeDimensionalArrays()
        {
            var original = new int[][][]
            {
                new int[][]
                {
                    new int[] { 1, 2 }
                },
                new int[][]
                {
                    new int[] { 1, 3, 5, 7, 9 },
                    new int[] { 11, 22 }
                },
            };
            var result = DeepCopier.Copy(original);

            Assert.Equal(original, result);
            Assert.NotSame(original, result);
        }
Example #31
0
 private void Merge(DeepCopier copier, Collection<VariableDefinition>def1, Collection<VariableDefinition> def2)
 {
     //TODO dont override destination instructions always
     def2.Clear();
     foreach(var v in def1){
         def2.Add(copier.Copy(v));
     }
 }
Example #32
0
 private void Merge(DeepCopier copier, Collection<Instruction>def1, Collection<Instruction> def2)
 {
     //TODO dont override destination instructions always, we migth gona need prepend
     def2.Clear();
     foreach(var i in def1){
         def2.Add(copier.Copy(i));
     }
 }