jeudi 14 juillet 2016

Compare list/IEnumerable type properties in Generic Method

I am trying to compare the object which contains List<> type properties. I am able to compare the simple properties but got stuck with complex one.

 foreach (PropertyInfo pi in properties)
     {
        object oldValue = pi.GetValue(oldObject), newValue = pi.GetValue(newObject);
        if (pi.PropertyType.IsGenericType && typeof(IEnumerable).IsAssignableFrom(pi.PropertyType))
        {
           Type type = oldValue.GetType().GetGenericArguments()[0];

           /* Need something like below commented line.*/
           // var added = newValue.Except(oldValue)
           // var removed = oldValue.Except(newValue);
        }}

In if block, i need to find the added and removed object in List type properties. In object we have Key attributed property to find added and removed object.





Aucun commentaire:

Enregistrer un commentaire