AutoMapper and reflection

automapper, reflection

Solution

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

[Edit]

Dont know of any that uses without reflection, even the one I had created XmlDataMapper on CodePlex uses reflection. It would difficult to design one without reflection or reflection.emit

The simplest and basic way to do this would be this, you can use any of the two or both techniques.

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; }
}

From the sample you have given where you are anyways trying to map property one by one, this is on the same lines, but with lesser code.

Problem

My shared hosting company doesn't allow Reflection. How can I use AutoMapper? Do I have to specify for each property a .ForMember? ``` Mapper.CreateMap<Person, PersonData>() .ForMember(dest => dest.Name, o => o.MapFrom(src => src.Name)) .ForMember(dest => dest.Address, o => o.MapFrom(src => src.Address)); ``` thanks, Filip

Original source