AutoMapper and reflection

My own hosting company does not allow Reflection. How to use AutoMapper?

Do I have to specify a.ForMember for each property?

Mapper.CreateMap<Person, PersonData>()
            .ForMember(dest => dest.Name, o => o.MapFrom(src => src.Name))
            .ForMember(dest => dest.Address, o => o.MapFrom(src => src.Address));

thank,

Filip

+3
source share
3 answers

Automapper uses reflection.emit, are you sure you can use Automapper?

[edit]

I don’t know what it uses without reflection, even the one I created XmlDataMapper in CodePlex uses reflection. It would be difficult to create one without reflection or reflection.

The easiest and easiest way to do this is to use either of two or both methods.

public class ConversionHelper
{
   public static ClassB Convert(ClassA item)
   {
      return new ClassB() { Id = item.Id, Name = item.Name };
   }

   public static List<ClassB> Convert(List<ClassA> list)
   {
      return list.Select(o => new ClassB() { Id = o.Id, Name = o.Name }).ToList();
   }
}


public class ClassA
{
   public int Id { get; set; }
   public string Name { get; set; }
}
public class ClassB
{
   public int Id { get; set; }
   public string Name { get; set; }
}

, , , , .

+5

Automapper , . . - ? .

+1

. AutoMapper . , AutoMapper .

0

Source: https://habr.com/ru/post/1778048/


All Articles