PD1991
Member
- Joined
- Nov 17, 2021
- Messages
- 18
- Programming Experience
- 1-3
Hello,
I have two list of object and I want to get added, removed and updated by comparing two List<Object>.
I have managed to get removed and added but I am not able to find out how I can get updated by comparing two List<Object>.
Eg.
oldValue = {
Name : Q1,
DataType: Bool,
IsActive: True
}
newValue = {
Name : Q1,
DataType: Bool,
IsActive: False
}
Than in updated list I want
newValue = {
Name : Q1,
DataType: Bool,
IsActive: False
}
Below is the code I am using for added and removed.
I have two list of object and I want to get added, removed and updated by comparing two List<Object>.
I have managed to get removed and added but I am not able to find out how I can get updated by comparing two List<Object>.
Eg.
oldValue = {
Name : Q1,
DataType: Bool,
IsActive: True
}
newValue = {
Name : Q1,
DataType: Bool,
IsActive: False
}
Than in updated list I want
newValue = {
Name : Q1,
DataType: Bool,
IsActive: False
}
Below is the code I am using for added and removed.
C#:
var removed = oldValue.Except(newValue, new AssignUserViewModelEqualityComparer()).ToList();
var added = newValue.Except(oldValue, new AssignUserViewModelEqualityComparer()).ToList();
class AssignUserViewModelEqualityComparer : IEqualityComparer<Qualifier>
{
public bool Equals(Qualifier x, Qualifier y)
{
if (object.ReferenceEquals(x, y))
return true;
if (x == null || y == null)
return false;
return x.Name.Equals(y.Name);
}
public int GetHashCode(Qualifier obj)
{
return obj.Name.GetHashCode();
}
}
public class Qualifier
{
[XmlElement(ElementName = "name")]
public string Name { get; set; }
[XmlElement(ElementName = "dataType")]
public string DataType { get; set; }
[XmlElement(ElementName = "isActive")]
public bool IsActive { get; set; }
}