public static CharacterUpdate Diff(CharacterSheet first, CharacterSheet second) { var firstAttribs = first.AttributeAllocations.Select(a => a.Attribute).Distinct(); var secondAttribs = second.AttributeAllocations.Select(a => a.Attribute).Distinct(); var removedAttribs = firstAttribs.Except(secondAttribs); var addedAttribs = secondAttribs.Except(firstAttribs); var removedAllocations = removedAttribs.Select(attrib => first.AttributeAllocations.First(a => a.Attribute == attrib)); var addedAllocations = addedAttribs.Select(attrib => second.AttributeAllocations.First(a => a.Attribute == attrib)); // updated if the allocation is unique to second but the attribute is present in the first var updatedAllocations = second.AttributeAllocations.Except(first.AttributeAllocations) .Where(a => firstAttribs.Contains(a.Attribute)); return new CharacterUpdate { AddedOrUpdatedAllocations = addedAllocations.Concat(updatedAllocations).ToList(), RemovedAllocations = removedAllocations.ToList(), }; }
public static CharacterUpdate Diff(CharacterSheet first, CharacterSheet second) { var firstAttribs = first.AttributeAllocations.Select(a => a.Attribute).Distinct(); var secondAttribs = second.AttributeAllocations.Select(a => a.Attribute).Distinct(); var removedAttribs = firstAttribs.Except(secondAttribs); var addedAttribs = secondAttribs.Except(firstAttribs); var removedAllocations = removedAttribs.Select(attrib => first.AttributeAllocations.First(a => a.Attribute == attrib)); var addedAllocations = addedAttribs.Select(attrib => second.AttributeAllocations.First(a => a.Attribute == attrib)); // updated if the allocation is unique to second but the attribute is present in the first var updatedAllocations = second.AttributeAllocations.Except(first.AttributeAllocations) .Where(a => firstAttribs.Contains(a.Attribute)); return(new CharacterUpdate { AddedOrUpdatedAllocations = addedAllocations.Concat(updatedAllocations).ToList(), RemovedAllocations = removedAllocations.ToList(), }); }