Ejemplo n.º 1
0
        public void ClassCopierNormal()
        {
            var pSource = new TestPerson()
            {
                Name    = "test",
                Address = "address",
                DOB     = new System.DateTime(1964, 3, 21),
                Salary  = 25000,
                Spouse  = "spouse"
            };
            var pTarget = new TestEmployee()
            {
                Name      = "target",
                Address   = "employee address",
                Birthdate = new System.DateTime(1962, 2, 2),
                Cost      = 15000,
                Position  = 5
            };

            ClassCopier <TestPerson, TestEmployee> .CopyClassProperties(pSource, pTarget);

            Assert.AreEqual(pSource.Name, pTarget.Name);
            Assert.AreEqual(pSource.Address, pTarget.Address);
            Assert.AreEqual(pSource.DOB, pTarget.Birthdate);
            Assert.AreEqual(pSource.Salary, pTarget.Cost);
            Assert.AreEqual("spouse", pSource.Spouse);
            Assert.AreEqual(5, pTarget.Position);
            Assert.IsNull(pTarget.Spouse);
        }
Ejemplo n.º 2
0
        public static T Copy <T>(this T source) where T : class, new()
        {
            Guard.NotNull(source, nameof(source));

            return(ClassCopier <T> .CopyThis(source));
        }