How to get the source hash code from a class that reimplement GetHashCode?

Short question: How to get the value of object.GetHashCode() for an object that was GetHashCode() ?

Long story: Thus, I have about one hundred thousand objects, each of which uses many (not compiled) common lines. As usual, if the value is equal, it is the same instance.

Knowing that, I suppose, I would prefer to use standard comparison of objects ( ReferenceEquals ), rather than full comparison of strings, especially if they look pretty regularly in dictionaries.

So, I declare a class ReferenceEqualityComparer : IEqualityComparer for use with Dictionary<string, TValue> , believing that it would be useful anyway, and try to implement two methods.

Equal values ​​are simple enough, use object.ReferenceEquals .

But how do I get the equivalent of object.GetHashCode() for the GetHashCode method?

that is, how do I get some idea of ​​an instance of an object?

I know that there are other ways I can do this: create an InternedString class that contains a reference to string but does not implement Equals or GetHashCode , or stores indexes, not strings with each object, but I'm now curious if there are any really a way to implement a generic ReferenceEqualityComparer ?

+3
source share
1 answer
+3
source

Source: https://habr.com/ru/post/897369/


All Articles