|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | + |
| 4 | +namespace GraphQL { |
| 5 | + |
| 6 | + /// <summary> |
| 7 | + /// A GraphQL request |
| 8 | + /// </summary> |
| 9 | + public class GraphQLRequest : IEquatable<GraphQLRequest?> { |
| 10 | + |
| 11 | + /// <summary> |
| 12 | + /// The Query |
| 13 | + /// </summary> |
| 14 | + public string Query { get; set; } |
| 15 | + |
| 16 | + /// <summary> |
| 17 | + /// The name of the Operation |
| 18 | + /// </summary> |
| 19 | + public string? OperationName { get; set; } |
| 20 | + |
| 21 | + /// <summary> |
| 22 | + /// Returns a value that indicates whether this instance is equal to a specified object |
| 23 | + /// </summary> |
| 24 | + /// <param name="obj">The object to compare with this instance</param> |
| 25 | + /// <returns>true if obj is an instance of <see cref="GraphQLRequest"/> and equals the value of the instance; otherwise, false</returns> |
| 26 | + public override bool Equals(object? obj) => this.Equals(obj as GraphQLRequest); |
| 27 | + |
| 28 | + /// <summary> |
| 29 | + /// Returns a value that indicates whether this instance is equal to a specified object |
| 30 | + /// </summary> |
| 31 | + /// <param name="other">The object to compare with this instance</param> |
| 32 | + /// <returns>true if obj is an instance of <see cref="GraphQLRequest"/> and equals the value of the instance; otherwise, false</returns> |
| 33 | + public bool Equals(GraphQLRequest? other) { |
| 34 | + if (other == null) { return false; } |
| 35 | + if (ReferenceEquals(this, other)) { return true; } |
| 36 | + if (!EqualityComparer<string>.Default.Equals(this.Query, other.Query)) { return false; } |
| 37 | + if (!EqualityComparer<string?>.Default.Equals(this.OperationName, other.OperationName)) { return false; } |
| 38 | + return true; |
| 39 | + } |
| 40 | + |
| 41 | + /// <summary> |
| 42 | + /// <inheritdoc cref="Object.GetHashCode"/> |
| 43 | + /// </summary> |
| 44 | + public override int GetHashCode() { |
| 45 | + unchecked { |
| 46 | + var hashCode = EqualityComparer<string>.Default.GetHashCode(this.Query); |
| 47 | + hashCode = (hashCode * 397) ^ EqualityComparer<string?>.Default.GetHashCode(this.OperationName); |
| 48 | + return hashCode; |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + /// <summary> |
| 53 | + /// Tests whether two specified <see cref="GraphQLRequest"/> instances are equivalent |
| 54 | + /// </summary> |
| 55 | + /// <param name="left">The <see cref="GraphQLRequest"/> instance that is to the left of the equality operator</param> |
| 56 | + /// <param name="right">The <see cref="GraphQLRequest"/> instance that is to the right of the equality operator</param> |
| 57 | + /// <returns>true if left and right are equal; otherwise, false</returns> |
| 58 | + public static bool operator ==(GraphQLRequest? left, GraphQLRequest? right) => EqualityComparer<GraphQLRequest?>.Default.Equals(left, right); |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// Tests whether two specified <see cref="GraphQLRequest"/> instances are not equal |
| 62 | + /// </summary> |
| 63 | + /// <param name="left">The <see cref="GraphQLRequest"/> instance that is to the left of the not equal operator</param> |
| 64 | + /// <param name="right">The <see cref="GraphQLRequest"/> instance that is to the right of the not equal operator</param> |
| 65 | + /// <returns>true if left and right are unequal; otherwise, false</returns> |
| 66 | + public static bool operator !=(GraphQLRequest? left, GraphQLRequest? right) => !(left == right); |
| 67 | + |
| 68 | + } |
| 69 | + |
| 70 | + public class GraphQLRequest<T> : GraphQLRequest, IEquatable<GraphQLRequest<T>?> { |
| 71 | + |
| 72 | + /// <summary> |
| 73 | + /// Represents the variables sended |
| 74 | + /// </summary> |
| 75 | + public T Variables { get; set; } |
| 76 | + |
| 77 | + /// <summary> |
| 78 | + /// Returns a value that indicates whether this instance is equal to a specified object |
| 79 | + /// </summary> |
| 80 | + /// <param name="obj">The object to compare with this instance</param> |
| 81 | + /// <returns>true if obj is an instance of <see cref="GraphQLRequest"/> and equals the value of the instance; otherwise, false</returns> |
| 82 | + public override bool Equals(object? obj) => this.Equals(obj as GraphQLRequest<T>); |
| 83 | + |
| 84 | + /// <summary> |
| 85 | + /// Returns a value that indicates whether this instance is equal to a specified object |
| 86 | + /// </summary> |
| 87 | + /// <param name="other">The object to compare with this instance</param> |
| 88 | + /// <returns>true if obj is an instance of <see cref="GraphQLRequest"/> and equals the value of the instance; otherwise, false</returns> |
| 89 | + public bool Equals(GraphQLRequest<T>? other) { |
| 90 | + if (other == null) { return false; } |
| 91 | + if (ReferenceEquals(this, other)) { return true; } |
| 92 | + if (!EqualityComparer<string>.Default.Equals(this.Query, other.Query)) { return false; } |
| 93 | + if (!EqualityComparer<string?>.Default.Equals(this.OperationName, other.OperationName)) { return false; } |
| 94 | + if (!EqualityComparer<dynamic?>.Default.Equals(this.Variables, other.Variables)) { return false; } |
| 95 | + return true; |
| 96 | + } |
| 97 | + |
| 98 | + /// <summary> |
| 99 | + /// <inheritdoc cref="Object.GetHashCode"/> |
| 100 | + /// </summary> |
| 101 | + public override int GetHashCode() { |
| 102 | + unchecked { |
| 103 | + return base.GetHashCode() * 397 ^ EqualityComparer<dynamic?>.Default.GetHashCode(this.Variables); |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + /// <summary> |
| 108 | + /// Tests whether two specified <see cref="GraphQLRequest"/> instances are equivalent |
| 109 | + /// </summary> |
| 110 | + /// <param name="left">The <see cref="GraphQLRequest"/> instance that is to the left of the equality operator</param> |
| 111 | + /// <param name="right">The <see cref="GraphQLRequest"/> instance that is to the right of the equality operator</param> |
| 112 | + /// <returns>true if left and right are equal; otherwise, false</returns> |
| 113 | + public static bool operator ==(GraphQLRequest<T>? left, GraphQLRequest<T>? right) => EqualityComparer<GraphQLRequest<T>?>.Default.Equals(left, right); |
| 114 | + |
| 115 | + /// <summary> |
| 116 | + /// Tests whether two specified <see cref="GraphQLRequest"/> instances are not equal |
| 117 | + /// </summary> |
| 118 | + /// <param name="left">The <see cref="GraphQLRequest"/> instance that is to the left of the not equal operator</param> |
| 119 | + /// <param name="right">The <see cref="GraphQLRequest"/> instance that is to the right of the not equal operator</param> |
| 120 | + /// <returns>true if left and right are unequal; otherwise, false</returns> |
| 121 | + public static bool operator !=(GraphQLRequest<T>? left, GraphQLRequest<T>? right) => !(left == right); |
| 122 | + |
| 123 | + } |
| 124 | + |
| 125 | +} |
0 commit comments