tags:

views:

33

answers:

2

i have two collections of the same objects (same size list of course). items can be matched by an IEqualityComparer (matching on a unique property of the object).

I want to generate a new list out of these existing lists that just show the field differences of each of the "same" items from each collection. I was thinking of doing something like this

List<ObjectFieldDiff> list = CalcList(origList1, origList2);

where

public class ObjectFieldDiffs
{
        public List<FieldDiff> FieldDiffs; 
}

public class FieldDiff
{
      public string PropertyName;
      public string Object1Value;
      public string Object2Value;
}

does this make sense. any suggestions?

A: 

(OK, I think this is going to be too long for a comment)

What do you mean by "Field Differences" and "'same' items" ?

class Point { public int X; public int Y;}

Point[] origList1 = new Point[1] {new Point() {X = 5, Y = 10}};
Point[] origList2 = new Point[1] {new Point() {X = 5, Y = 11}};

List<ObjectFieldDiff> list = CalcList(origList1, origList2); 

What exactly do you expect in list ?

From what I can gleen from you question, it would be:

new List<FieldDiff>(1) {new FieldDiff() {ValueObject1=10, ValueObject2=11}};

which is of minimal use (no idea which objects mismatch, no idea which field in the object mismatch)

James Curran
@James Curran - the only addition is that there is a property on FieldDiff which would have "Y" in it to show the name of the different property
ooo
+1  A: 

That seems reasonable, perhaps I would just add links to the two objects in question.

public class FieldDiff
{
  public object Object1;
  public object Object2;
  public string PropertyName;
  public object Object1Value;
  public object Object2Value;
}

Alternatively, if all of the properties are numeric, you could just store a difference:

public class FieldDiff
{
  public object Object1;
  public object Object2;
  public string PropertyName;
  public object ValueDifference;
}
dsolimano