I’m looking to remove all elements in a list that can be compared to elements of another list of a different type that don’t share a common inheretence, but I do have an equality function for. An example might make it clearer:
given the scaffolding
bool isSomeSortOfEqual(Bottle b, Printer p){
//implementation
}
List<Bottle> bottles = getBottles();
List<Printer> printers = getPrinters();
I would like to do something like this:
List<Bottle> result = bottles.Except(printers, (b, p => isSomeSortOfEqual(b, p));
Are there any builtins for this in .NET, or should I implement this by hand? None of the questions relating to relative complement or except in .NET on stackoverflow seem to deal with having different types.
How about this? The basic idea is to cast the lists to
List<object>and then use .Except with anIEqualityComparer<object>