To my knowledge, there isn't such a converter available within the framework as of .NET 4.0. You could write one yourself, however:
public class ComparisonComparer<T> : Comparer<T>
{
private readonly Func<T, T, int> _comparison;
public MyComparer(Func<T, T, int> comparison)
{
if (comparison == null)
throw new ArgumentNullException("comparison");
_comparison = comparison;
}
public override int Compare(T x, T y)
{
return _comparison(x, y);
}
}
EDIT: This of course assumes that the delegate can deal with null-arguments in a conformant way. If it doesn't, you can handle those within the comparer - for example by changing the body to:
if (x == null)
{
return y == null ? 0 : -1;
}
if (y == null)
{
return 1;
}
return _comparison(x, y);