I\'m looking at how build the best HashCode for a class and I see some algorithms. I saw this one : Hash Code implementation, seems to be that .NET classes HashCode methods
Instead of calling keys[i].GetType().IsArray
, you should try to cast it to IEnumerable
(using the as
keyword).
You can fix the Equals
method without repeating the field list by registering a static list of fields, like I do here using a collection of delegates.
This also avoids the array allocation per-call.
Note, however, that my code doesn't handle collection properties.