tags:

views:

52

answers:

0

The question stems from database tables comparison. Let's say we put left row in the instance Left and the right one into instance Right of the same type. And we'got many tables and respective types.

How to implement more or less generic routine resulting in a collection of diffs e.g.
propertyName , leftValue , rightValue for each such a pair of instances of the same type. Apart from generic algorithm of comparison since leftValue and rightValue can be anything ( pair of strings or int or DateTime or Guid ) is not obvious how to combine all that in one collection.

EDIT:

class OneOfManyTypesBasedOnTableRow 
{
   Guid uid,
   int  anotherId,
   string text1,
   string text2,
   DateTime date1, 
   DateTime date2 
}
class AnotherOfManyTypesBasedOnTableRow 
{
   Guid uid,
   int  anotherId,
   string text3,
   string text4,
   DateTime date3, 
   DateTime date4 
}

//For type 1
OneOfManyTypesBasedOnTableRow  Left =  new Something().GetLeft() ;
OneOfManyTypesBasedOnTableRow  Right =  new Something().GetRight() ;
DiffCollection1 diff1 = comparer.GetDiffForOneOfManyTypesBasedOnTableRow ( Left , Right ) ;   

//For type 2

AnotherOfManyTypesBasedOnTableRow  Left =  new SomethingElse().GetLeft() ;
AnotherOfManyTypesBasedOnTableRow  Right =  new SomethingElse().GetRight() ;
DiffCollection2 diff2 = comparer.GetDiffForAnotherOfManyTypesBasedOnTableRow ( Left , Right ) ;   

My problem is that I don't know how to avoid repetition of that quite similar code for each type. It might be ok for objects population . But in diff methods I have to code

if Left.Text1.Equals ( Right.Text1 ) 

and so on in one method

if Left.Text3.Equals ( Right.Text3 ) 

and so on in other method