If I have:
IEnumerable<CrewBase> crewBasesLeft;
IEnumerable<CrewBase> crewBasesRight;
and do:
IEnumerable<CrewBase> intersect = crewBasesLeft
.Intersect( crewBasesRight,CrewBaseComparer.OnId() );
How do I get:
CrewBase left;
CrewBase right;
from the:
intersect
so I can loop over all the CrewBases in the Intersect and make a call:
Action(left,right);
I only want to do this on CrewBases that are equal in both list according to my CrewBaseComparer.OnId that implements:
IEqualityComparer<CrewBase>
This is my current implementation:
IEnumerable<ObjectDifference> GetCrewBaseDifferences2( TrafficPlan left, TrafficPlan right )
{
var result = new List<ObjectDifference>();
IEnumerable<CrewBase> intersect = left.CrewBases.Intersect( right.CrewBases,CrewBaseComparer.OnId() );
foreach( CrewBase crewBase in intersect )
{
CrewBase other = crewBase;
ObjectDifference diff = crewBase.GetDifference( right.CrewBases.First(x => x.Equals(other, CrewBaseComparer.OnId())) );
if( diff.HasDifferences )
{
result.Add( diff );
}
}
return result;
}