예제 #1
0
        static MappingOptions()
        {
            DefaultClone = new MappingOptions
            {
                Mode = MappingMode.Clone,

                IgnoreNulls = false,

                ReuseTargetCollectionsWhenPossible = true,
                ReuseTargetCollectionItemsWhenPossible = true,
                TrackReferences = true,
                IgnorePrivateTypes = true
            };

            DefaultCopy = new MappingOptions
            {
                Mode = MappingMode.Copy,

                IgnoreNulls = false,

                ReuseTargetCollectionsWhenPossible = false,
                ReuseTargetCollectionItemsWhenPossible = false,
                TrackReferences = false,
                IgnorePrivateTypes = true
            };
        }
        public IDiagnosticsConfiguration GetConfigurationClone()
        {
            var mo = new MappingOptions();
            mo.ReuseTargetCollectionItemsWhenPossible = false;
            mo.ReuseTargetCollectionsWhenPossible = false;
            mo.TrackReferences = false;

            return ConfigTypeMapper.DeepClone<DiagnosticsConfiguration>(Config, mo);
        }
        public void Bug006_ReuseTargetCollectionsWhenPossible_false__Fails_to_create_new_collection()
        {
            var c1 = new Bug006_Class_One { Name = "1" };

            var trp1 = new Bug006_Class_One
            {
                Name = "trp1"
            };
            var trp2 = new Bug006_Class_One
            {
                Name = "trp2"
            };

            c1.Items.Add(trp1);
            c1.Items.Add(trp2);

            var c2 = new Bug006_Class_One();

            var mo = new MappingOptions()
            {
                ReuseTargetCollectionsWhenPossible = false,
            };

            var tm = new TypeMapper();

            tm.Map(c1, c2, mo);

            Assert.AreEqual(c1.Name, c2.Name);

            // when the bug wasn't fixed, c2.Items.Count would be 0
            Assert.AreEqual(c1.Items.Count, c2.Items.Count);

            for (int i = 0; i < c1.Items.Count; i++)
            {
                Assert.AreEqual(c1.Items[i].Name, c2.Items[i].Name);
            }
        }