graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

Strip down or remove GetHashCode / Equals

Open sungam3r opened this issue 5 years ago • 1 comments
trafficstars

I have long wanted to ask what is the reason for the presence of such code.

 public override int GetHashCode()
        {
            unchecked
            {
                var hashCode = EqualityComparer<T>.Default.GetHashCode(Data);
                {
                    if (Errors != null)
                    {
                        foreach (var element in Errors)
                        {
                            hashCode = (hashCode * 397) ^ EqualityComparer<GraphQLError?>.Default.GetHashCode(element);
                        }
                    }
                    else
                    {
                        hashCode = (hashCode * 397) ^ 0;
                    }

                    if (Extensions != null)
                    {
                        foreach (var element in Extensions)
                        {
                            hashCode = (hashCode * 397) ^ EqualityComparer<KeyValuePair<string, object>>.Default.GetHashCode(element);
                        }
                    }
                    else
                    {
                        hashCode = (hashCode * 397) ^ 0;
                    }
                }
                return hashCode;
            }
        }


        public static bool operator ==(GraphQLResponse<T>? response1, GraphQLResponse<T>? response2) => EqualityComparer<GraphQLResponse<T>?>.Default.Equals(response1, response2);

        public static bool operator !=(GraphQLResponse<T>? response1, GraphQLResponse<T>? response2) => !(response1 == response2);

It takes up quite a bit of space and is repeated for GraphQLError, GraphQLLocation, GraphQLRequest, GraphQLResponse . I want to note right away that I understand what this code is doing. I don’t understand why this is necessary and whether it makes sense. It always seemed to me redundant. My suggestion is to remove all this code and thereby simplify the perception of the rest.

@rose-a Also, some time ago, I wrote that sooner or later I’ll take up the review of this project since I have plans for its reverse integration into my projects. The time has come.

sungam3r avatar Apr 03 '20 16:04 sungam3r

:+1: for the time which has now come 😉

Those where already in the project when I started contributing to it...

I think the only situation where this is actually used is here.

I think we should strip that down as much as possible (it confuses me too), but I didn't dig into it yet.

rose-a avatar Apr 04 '20 20:04 rose-a