Beispiel #1
0
        private static void MapPersonComplex()
        {
            TinyMapper.Bind <PersonComplex, PersonDtoComplex>(config =>
            {
                config.Ignore(source => source.CreateTime);
                config.Ignore(source => source.Nickname);
                config.Bind(source => source.LastName, target => target.Surname);
                config.Bind(target => target.Emails, typeof(List <string>));
            });

            var person = new PersonComplex
            {
                Id        = Guid.NewGuid(),
                FirstName = "John",
                LastName  = "Doe",
                Address   = new Address
                {
                    Phone   = "Call Me Maybe",
                    Street  = "Wall Street",
                    ZipCode = "101000"
                },
                CreateTime = DateTime.Now,
                Nickname   = "Object Mapper",
                Emails     = new List <string>
                {
                    "*****@*****.**",
                    "*****@*****.**"
                }
            };

            var personDto = TinyMapper.Map <PersonDtoComplex>(person);
        }
 private void ImplementingISerialization()
 {
     Console.WriteLine("Implementing ISerializable Interface with method GetObjectData to secure the public fields value");
     PersonComplex person = new PersonComplex { Id = 3, Name = "Mayank" };
     IFormatter formatter = new BinaryFormatter();
     using (MemoryStream stream = new MemoryStream())
     {
         formatter.Serialize(stream, person);
         stream.Position = 0;
         PersonComplex personcomplex = (PersonComplex)formatter.Deserialize(stream);
         Console.WriteLine("Deserialized person is with Id:{0} whose name is {1}", personcomplex.Id, personcomplex.Name);
     }
 }
        private void ImplementingISerialization()
        {
            Console.WriteLine("Implementing ISerializable Interface with method GetObjectData to secure the public fields value");
            PersonComplex person = new PersonComplex {
                Id = 3, Name = "Mayank"
            };
            IFormatter formatter = new BinaryFormatter();

            using (MemoryStream stream = new MemoryStream())
            {
                formatter.Serialize(stream, person);
                stream.Position = 0;
                PersonComplex personcomplex = (PersonComplex)formatter.Deserialize(stream);
                Console.WriteLine("Deserialized person is with Id:{0} whose name is {1}", personcomplex.Id, personcomplex.Name);
            }
        }
        public void Map_To_IEnumerable_Success()
        {
            var target = new PersonComplex
            {
                Emails    = new[] { "*****@*****.**", "*****@*****.**" },
                FirstName = "John",
                LastName  = "Doe"
            };

            _tinyMapper.Bind <PersonComplex, PersonComplexTarget4>();

            var actual = _tinyMapper.Map <PersonComplexTarget4>(target);

            XAssert.Equal(target.FirstName, actual.FirstName);
            XAssert.Equal(target.LastName, actual.LastName);
            XAssert.Equal(target.Emails, actual.Emails.Cast <string>());
        }
        public void Map_IEnumerable_T_Success()
        {
            var target = new PersonComplex
            {
                Emails    = new[] { "*****@*****.**", "*****@*****.**" },
                FirstName = "John",
                LastName  = "Doe"
            };

            TinyMapper.Bind <PersonComplex, PersonComplexTarget>();

            var actual = TinyMapper.Map <PersonComplexTarget>(target);

            Assert.Equal(target.FirstName, actual.FirstName);
            Assert.Equal(target.LastName, actual.LastName);
            Assert.Equal(target.Emails, actual.Emails);
        }
 public static void Start()
 {
     var personComplex = new PersonComplex();
 }