Exemplo n.º 1
0
        object ICloneable.Clone()
        {
            var rval = new ExampleOldSchoolList() as IList;
            var max  = this.Count;
            var self = this as IList;

            for (var i = 0; i < max; i++)
            {
                rval.Add((self[i] as Item).Clone());
            }

            return(rval);
        }
Exemplo n.º 2
0
        public static ExampleOldSchoolList GenerateExampleObject()
        {
            var rval = new ExampleOldSchoolList();

            for (var i = 0; i < 10; i++)
            {
                (rval as IList).Add(
                    new Item
                {
                    FieldA = "asdf",
                    FieldB = "1234",
                    FieldC = "xxxx"
                }
                    );
            }

            return(rval);
        }
Exemplo n.º 3
0
        public void TestNonGenericListCloning()
        {
            var ilCloner = new IlCloner();

            var example = new AsList
            {
                "A", "B", "C"
            };

            var cloner = ilCloner.CreateClonerDelegate <AsList>();

            var cloned = cloner(example);

            Assert.IsFalse(Object.ReferenceEquals(example, cloned));
            Assert.IsTrue(example.SequenceEqual(cloned));

            var nonGenList = new ExampleOldSchoolList();

            ((IList)nonGenList).Add(example);
            ((IList)nonGenList).Add(example);
            ((IList)nonGenList).Add(example);
            ((IList)nonGenList).Add(example);
            ((IList)nonGenList).Add(example);
            ((IList)nonGenList).Add(example);

            var clonerNonGen = IlCloner.CreateCloner(nonGenList);
            var clonedNonGen = clonerNonGen(nonGenList);

            Assert.IsFalse(Object.ReferenceEquals(nonGenList, clonedNonGen));
            Assert.IsTrue(example.SequenceEqual(cloned));

            for (var i = 0; i < nonGenList.Count; i++)
            {
                Assert.IsFalse(Object.ReferenceEquals(((IList)nonGenList)[i], ((IList)clonedNonGen)[i]));
            }
        }