Base types, Collections, Diagnostics, IO, RegEx…
In an effort to keep the design of generics really clean, we decided not to mix the generic and non generic model. To solve the above scenario, you can subclass IComparer<T>:IComparer. However, this would mean that all implementors of IComparer <T> would have to provide a non-generic implementation as well.
Ryan Byington gave me another great suggestion; create a thin wrapper for the IComparer implementation that implements IComparer<T>.
public class WeaklyTypedComparerWrapper<T> : IComparer<T>
public WeaklyTypedComparerWrapper(IComparer comparer)
_comparer = comparer;
public int Compare(T item1, T item2)
return _comparer.Compare(item1, item2);
If you have a scenario where you *must* be able to pass in a non-generic version of IComparer to a generic collection, let us know!