Reputation: 842
I have my class
MyClass<MyTriple<FirstG, SecondG, ThirdG>> : ICollection<MyTriple<FirstG, SecondG, ThirdG>>
I have data stored in:
Dictionary<FirstG, Dictionary<SecondG, ThirdG>> Data
and I want to implement IEqualityComparer
for my Data. Constructor of MyClass
has to take as argument comparer of MyTriple
:
public MyClass(IEqualityComparer<MyTriple<FirstG, SecondG, ThirdG>> comparer) {...}
and I want (somehow) pass this comparer to Data
and create it in constructor like:
Data = new Dictionary<FirstG, new Dictionary<SecondG, ThirdG>(SecondAndThirdGComparer)>(FirstGComparer);
I am really hopeless, I tried creating my comparer that implements IEqualityComparer
, but I can't figure out, how to get FirstGComparer<FirstG>
comparer. Thanks for any advices.
Upvotes: 0
Views: 121
Reputation: 61952
OK, so the user comes in with a comparer
parameter (to the constructor) of type:
IEqualityComparer<MyTriple<FirstG, SecondG, ThirdG>>
Now, that could be any crazy comparer in "3D". No-one can guarantte that this comparer
works in a coordinate-wise or lexicographic way. Therefore there's absolutely no way you can "factor" out a comparer of only FirstG
, for example.
Suppose you have two instances firstG_X
and firstG_Y
, say. Then from comparer
you cannot tell whether these two are equal. You can ask comparer
to compare two triples only. If you "extend" firstG_X
to some triple, and firstG_Y
to some other triple, you have to make an arbitrary choice, and the answer from the oraculous comparer
might very well depend on that choice.
Hoping what I'm saying makes sense.
Upvotes: 3