something is not right on the hascode

Oystein Bjorke 10 year бұрын 0
This discussion was imported from CodePlex

chage wrote at 2014-03-27 23:46:

Hi Objo,
While testing, I found an issue where i added a series into a dictionary as key and later retrieve it using the series as a key. Exception is thrown claiming no such key.

After some digging of this weird behaviour, i believe it comes down to the a new added gethashcode override method in PlotElememt.
public override int GetHashCode()
        {
            // Get the values of all properties in the object (this is slow, any better ideas?)
            var propertyValues = this.GetType().GetProperties().Select(pi => pi.GetValue(this, null));
            return propertyValues.GetHashCode();
        }
I can't tell whats wrong with this method of using reflection to retrieve properties value, but a simple test shows that this is not working.
LineSeries series = new LineSeries();
int hash1 = series.GetHashCode();
int hash2 = series.GetHashCode(); // different hash returned...
Any idea? thanks!