/// <summary> /// Diff two lists. Does not currently /// </summary> /// <param name="baseObj"></param> /// <param name="antagonist"></param> /// <returns></returns> internal IEnumerable <BaseDiff> DiffList(IEnumerable <object> baseObj, IEnumerable <object> antagonist) { var results = new List <BaseDiff>(); // 1. Ensure the lists are the same size var baseSize = baseObj.Count(); var antagonistSize = antagonist.Count(); // If these aren't the same size, don't run the Diff, just mention that it differs in length. if (baseSize != antagonistSize) { var result = new BaseDiff { BaseValue = baseObj, EvaluatedValue = antagonist, Message = DiffMessage.DiffersInLength }; results.Add(result); return(results); } // Determine the Error Message for mismatches in the list var errorMessage = DiffMessage.DiffersInContent; if (baseObj.All(n => n is IComparable) && antagonist.All(m => m is IComparable)) { // Sort the Base var sortedBase = baseObj.ToList(); sortedBase.Sort(); // Sort the Eval var sortedAntagonist = antagonist.ToList(); sortedAntagonist.Sort(); // If the content is equal, then the order is the only thing that can differ if (ContentIsEqual(sortedBase, sortedAntagonist)) { errorMessage = DiffMessage.DiffersInOrder; } } // Check values foreach (var item in baseObj.Zip(antagonist)) { var result = DiffObjects( baseObj: item.Key, evaluated: item.Value); // Change the error message if the values don't match result.Message = result.ValuesMatch ? DiffMessage.NotApplicable : errorMessage; results.Add(result); } return(results); }
/// <summary> /// Diff two lists. Does not currently /// </summary> /// <param name="baseObj"></param> /// <param name="antagonist"></param> /// <returns></returns> internal IEnumerable<BaseDiff> DiffList(IEnumerable<object> baseObj, IEnumerable<object> antagonist) { var results = new List<BaseDiff>(); // 1. Ensure the lists are the same size var baseSize = baseObj.Count(); var antagonistSize = antagonist.Count(); // If these aren't the same size, don't run the Diff, just mention that it differs in length. if (baseSize != antagonistSize) { var result = new BaseDiff { BaseValue = baseObj, EvaluatedValue = antagonist, Message = DiffMessage.DiffersInLength }; results.Add(result); return results; } // Determine the Error Message for mismatches in the list var errorMessage = DiffMessage.DiffersInContent; if(baseObj.All(n => n is IComparable) && antagonist.All(m => m is IComparable)) { // Sort the Base var sortedBase = baseObj.ToList(); sortedBase.Sort(); // Sort the Eval var sortedAntagonist = antagonist.ToList(); sortedAntagonist.Sort(); // If the content is equal, then the order is the only thing that can differ if (ContentIsEqual(sortedBase, sortedAntagonist)) { errorMessage = DiffMessage.DiffersInOrder; } } // Check values foreach (var item in baseObj.Zip(antagonist)) { var result = DiffObjects( baseObj: item.Key, evaluated: item.Value); // Change the error message if the values don't match result.Message = result.ValuesMatch ? DiffMessage.NotApplicable : errorMessage; results.Add(result); } return results; }