Skip to content

Strip down or remove GetHashCode / Equals #208

Open
@sungam3r

Description

@sungam3r

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions