For example I now created a this tiny class:
public static class FileSystemInfoComparers<T> where T : FileSystemInfo
{
public static IEqualityComparer<T> FullName
{
get { return new FullNameComparer(); }
}
private class FullNameComparer : IEqualityComparer<T>
{
public bool Equals(T x, T y) { return x.FullName == y.FullName; }
public int GetHashCode(T obj) { return obj.FullName.GetHashCode(); }
}
}
I would like it if I could just do
var comparer = FileSystemInfoComparers.FullName;
and have an instance of IEqualityComparer<FileSystemInfo>
, since I didn't specify any type and FileSystemInfo is the most generic type T can be. With no type constraint the default type could for example be object or something.
Maybe not the best example, but anyways just got curious here :p