Currently the HashSet<T>
constructor that allows you to define your equality comparison yourself is the HashSet<T>(IEqualityComparer<T> comparer)
constructor.
I would like to define this EqualityComparer as a lambda.
I found this blog post that has made a class that allows you to generate your comparer through lambda and then hides the construction of this class with an extention method to do for example an Except().
Now I would like to do the same but with a constructor. Is it possible to create a constructor through an extention method? Or is there another way I could somehow create a HashSet<T>(Func<T,T,int> comparer)
?
--UPDATE--
For clarity, this is (a snippet of) a freehand version of what I'm trying to accomplish:
HashSet<FileInfo> resultFiles = new HashSet<FileInfo>(
srcPath.GetFiles(),
new LambdaComparer<FileInfo>(
(f1, f2) => f1.Name.SubString(10).Equals(f2.Name.SubString(10))));
or more ideally
HashSet<FileInfo> resultFiles = new HashSet<FileInfo>(
srcPath.GetFiles(),
(f1, f2) => f1.Name.SubString(10).Equals(f2.Name.SubString(10)));