IComparer<> through a 'static' definition ?

  • Thread starter Thread starter Michel Walsh
  • Start date Start date
M

Michel Walsh

I got a class which implements a comparison test:

public class CompareMarque : ICompare<Marque>
{
public int Compare( Marque x, Marque y)
{
...some funny rules
}


// but I also want to be able to use the same funny rules in a static way,
so I added:

public static int Comparez( Marque x, Marque y)
{
... SAME funny rules
}
}



Question: is there a way to AVOID code duplication of the "funny rules"
(since it seems that a static method CANNOT be used to implement ICompare) ?



Vanderghast, Access MVP
 
.... well, can also use a call to the static definition within the non-static
definition... doh... Looking too hard in the wrong direction, I guess...
Sorry for the bandwidth.


Vanderghast, Access MVP
 
hi Michael,

Michel said:
public class CompareMarque : ICompare<Marque>
{
public int Compare( Marque x, Marque y)
{
}
// but I also want to be able to use the same funny rules in a static way,
so I added:
public static int Comparez( Marque x, Marque y)
{
}
}
This should be a clean solution:

public class CompareMarque : ICompare<Marque>
{
int ICompare<Marque>.Compare( Marque x, Marque y)
{
return Compare(x, y);
}

public static int Compare( Marque x, Marque y)
{
return 0;
}
}



mfG
--> stefan <--
 
Back
Top