Need help!

Sep 20, 2012 at 12:17 PM
Edited Sep 20, 2012 at 12:31 PM

Can I use valueInjecter to map an EntityDTO to Entity (or Entity to EntityDTO)? 

        public static Person GetPerson(PersonDTO dto)
        {
            var entity = new Person();
            entity.InjectFrom(dto);
            return entity;
        }

The problem is that entity.Name will be null.

In my case the property types for Name and Address are different (Name != NameDTO, Address != AddressDTO) but with the same structure.

 

    public class Person
    {
        public string Id { get; set; }
        public Name Name { get; set; }
    }

    public class Name
    {
        public string FirstName { get; set; }
        public Address Address { get; set; }
    }

    public class Address
    {
        public string Location { get; set; }
    }


    public class PersonDTO
    {
        public string Id { get; set; }
        public NameDTO Name { get; set; }
    }

    public class NameDTO
    {
        public string FirstName { get; set; }
        public AddressDTO Address { get; set; }
    }

    public class AddressDTO
    {
        public string Location { get; set; }
    }

Sep 20, 2012 at 12:30 PM

the default injectfrom is not gonna work because types are different (Name NameDto)

what you need is a custom injection that will not check for type but just for name equality

and do a simple assignment for valuetypes and strings, and call itself for object types

Sep 20, 2012 at 12:37 PM
Edited Sep 20, 2012 at 12:37 PM

I hoped that there were such a custom injection. Thanks!