using System; using System.Collections.Generic; using System.Text; using System.Reflection; namespace sharpcomparer { public class UserComparison : Comparison { public short Uid { get { return LeftItem != null ? LeftItem.Uid : RightItem.Uid; } } public string UserName { get { return LeftItem != null ? LeftItem.UserName : RightItem.UserName; } } public UserComparison(User leftItem, User rightItem, Comparison.ComparisonDifference difference) : base(leftItem, rightItem, difference) { } public static List Compare(List left, List right) { List comparison = new List(); foreach (User item in left) { User result = right.Find( delegate(User find) { return find.Uid == item.Uid; } ); if (result != null) { if (item != result) { comparison.Add(new UserComparison(item, result, ComparisonDifference.Different)); } else { comparison.Add(new UserComparison(item, result, ComparisonDifference.None)); } } else { comparison.Add(new UserComparison(item, null, ComparisonDifference.LeftOnly)); } } foreach (User item in right) { User result = left.Find( delegate(User find) { return find.Uid == item.Uid; } ); if (result == null) { comparison.Add(new UserComparison(null, item, ComparisonDifference.RightOnly)); } } return comparison; } } }