开发者

return field diffs from 2 collections

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?


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;
}


(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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜