✅ 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?
Gist
t.cs
GitHub Gist: instantly share code, notes, and snippets.
16 Replies
canton7
canton7•6mo ago
Use a custom IEqualityComparer<T>?
cap5lut
cap5lut•6mo ago
wouldnt help much because they need TypeKey anyway for the hashcode
canton7
canton7•6mo ago
What? Why not? This is literally why Dictionary takes an IEqualityComparer<T>
cap5lut
cap5lut•6mo ago
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
canton7
canton7•6mo ago
Again, why not?
cap5lut
cap5lut•6mo ago
so u want a TypeKey + an IEqualityComparer<TypeKey> to simplify it?
canton7
canton7•6mo ago
No, no TypeKey
cap5lut
cap5lut•6mo ago
but u cant represent type.IsGenericType ? type.GetGenericTypeDefinition().GetHashCode() : type.GetHashCode() with the equality comparerer
canton7
canton7•6mo ago
Why not?
cap5lut
cap5lut•6mo ago
wait, i think im thinking wrong here yeah im dumb ._.
canton7
canton7•6mo ago
🙂
cap5lut
cap5lut•6mo ago
u wouldnt need to override the hashcode method, thus the equality comparer would be enough
canton7
canton7•6mo ago
Yep No overrides at all
Joreyk ( IXLLEGACYIXL )
how can i give the dictionary the iequality comparer to use that one "always" instead of the default one
canton7
canton7•6mo ago
There's a constructor parameter
Joreyk ( IXLLEGACYIXL )
ah oke thanks
Want results from more Discord servers?
Add your server
More Posts