Ok, I fully understood your question in the first answer. It's better here:)
Overloads are your best bet. Since the result of the comparison depends only on Name , create a method that performs this comparison, then name it:
private int Compare(string first, string second) {
Edit:
Since you have several elements, you can do two things:
public int Compare(string first1, string second1, X first2, X second2 ...
But it will be a little ugly. An alternative is to provide a projection for extracting values:
private int Compare<T>(T first, T second, Func<T,Tuple<string,int,TypeX,TypeY>> projection) {
Then your comparison looks something like this:
int Compare(Type1 first, Type1 second) { return Compare(first, second, x => Tuple.Create(x.Name, x.Int, xX, xY)); }
source share