Difference between two lists

前端 未结 12 1278
无人共我
无人共我 2020-11-22 13:19

I Have two generic list filled with CustomsObjects.

I need to retrieve the difference between those two lists(Items who are in the first without the items in the sec

12条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 13:38

    bit late but here is working solution for me

     var myBaseProperty = (typeof(BaseClass)).GetProperties();//get base code properties
                        var allProperty = entity.GetProperties()[0].DeclaringType.GetProperties();//get derived class property plus base code as it is derived from it
                        var declaredClassProperties = allProperty.Where(x => !myBaseProperty.Any(l => l.Name == x.Name)).ToList();//get the difference
    

    In above mention code I am getting the properties difference between my base class and derived class list

提交回复
热议问题