✅ How to Simplify
I have this https://gist.github.com/IXLLEGACYIXL/399c51cf0341188bdc4e02a820c34ce0
I need the generictypedefinitions hash and not the "normal" hashcode of the type
now i wrote that to "override" the gethashcode to get the generic one, isnt there a simpler way to achieve that?
16 Replies
Use a custom
IEqualityComparer<T>
?wouldnt help much because they need
TypeKey
anyway for the hashcodeWhat? Why not?
This is literally why
Dictionary
takes an IEqualityComparer<T>
that wouldnt help with the custom
GetHashCode()
method, so they need TypeKey
,
thus they can also implement the equality check as the natural one, by overriding Equals
Again, why not?
so u want a
TypeKey
+ an IEqualityComparer<TypeKey>
to simplify it?No, no
TypeKey
but u cant represent
type.IsGenericType ? type.GetGenericTypeDefinition().GetHashCode() : type.GetHashCode()
with the equality comparererWhy not?
wait, i think im thinking wrong here
yeah im dumb ._.
🙂
u wouldnt need to override the hashcode method, thus the equality comparer would be enough
Yep
No overrides at all
how can i give the dictionary the iequality comparer to use that one "always" instead of the default one
There's a constructor parameter
ah oke
thanks