0

I have a list of objects in c#. And one object in the list contains 30 properties. I have another list of array which contains names of those property and it could be of any length say 10 or 20. My requirement is to assign null values to all those properties(in that list of object) which are not present in that array using automapper. See below code

What I did till now:

foreach(var item in ListItems)
{
    foreach(var prop in item.GetType().GetProperties())
    {
        var itemExist = SecondList.SingleOrDefault(x=>...some logic)
        if(itemExist!=null)
        {
            item.GetType().GetProperty($"{prop.name}").SetValue(item, null);
        }
    }
}

This code is working fine but I am aiming to do this using AutoMapper. Any help would be much appreciate. Thanks!

gorak
  • 1
  • 1

0 Answers0