I have created a generic method for mapping between List. It was working fine up to AutoMapper Version 3.3.1. After Version 4.0.0 its not working
public class Helper<T> : List<T> where T : new()
{
public void MapBetween(List<T> NewList, List<T> OldList)
{
try
{
foreach (var NewItem in NewList)
{
string PrimaryKey = NewItem.GetType().GetProperties().First(f => f.Name.ToLower() == typeof(T).Name.ToLower() + "id").GetValue(NewItem).ToString();
var OldItem = OldList.Find(delegate(T p) { return p.GetType().GetProperties()[0].GetValue(p).Equals(PrimaryKey); });
AutoMapper.Mapper.DynamicMap(NewItem, OldItem);//Mapping
}
}
catch (Exception ex)
{
throw ex;
}
}
}
public class Ac
{
public string AcId { get; set; }
public string A { get; set; }
public string B { get; set; }
}
public void ConvertList()
{
List<Ac> OldList = new List<Ac>();
OldList.Add(new Ac { AcId = "1", A = "Old A", B = "Old B" });
List<Ac> NewList = new List<Ac>();
NewList.Add(new Ac { AcId = "1", A = "new A", B = "new B" });
Helper<Ac> helper = new Helper<Ac>();
helper.MapBetween(NewList, OldList);
}
Is there is any changes required in my approach?