コード例 #1
0
        public void Equals_should_return_expected_result(
            int port1,
            int localValue1,
            int serverValue1,
            int port2,
            int localValue2,
            int serverValue2,
            bool expectedEqualsResult,
            bool expectedStructurallyEqualsResult)
        {
            var clusterId = new ClusterId();
            var serverId1 = new ServerId(clusterId, new DnsEndPoint("localhost", port1));
            var serverId2 = new ServerId(clusterId, new DnsEndPoint("localhost", port2));

            var subject1 = new ConnectionId(serverId1, localValue1).WithServerValue(serverValue1);
            var subject2 = new ConnectionId(serverId2, localValue2).WithServerValue(serverValue2);

            // note: Equals ignores the server values and StructurallyEquals compares all fields
            var equalsResult1 = subject1.Equals(subject2);
            var equalsResult2 = subject2.Equals(subject1);
            var structurallyEqualsResult1 = subject1.StructurallyEquals(subject2);
            var structurallyEqualsResult2 = subject2.StructurallyEquals(subject1);
            var hashCode1 = subject1.GetHashCode();
            var hashCode2 = subject2.GetHashCode();

            equalsResult1.Should().Be(expectedEqualsResult);
            equalsResult2.Should().Be(expectedEqualsResult);
            structurallyEqualsResult1.Should().Be(expectedStructurallyEqualsResult);
            structurallyEqualsResult2.Should().Be(expectedStructurallyEqualsResult);
            (hashCode1 == hashCode2).Should().Be(expectedEqualsResult);
        }
コード例 #2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (connectionId_ != null)
            {
                hash ^= ConnectionId.GetHashCode();
            }
            if (AppId.Length != 0)
            {
                hash ^= AppId.GetHashCode();
            }
            if (appInstanceId_ != null)
            {
                hash ^= AppInstanceId.GetHashCode();
            }
            if (TransportType != global::Plexus.Interop.Apps.Internal.Generated.TransportType.Unknown)
            {
                hash ^= TransportType.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
コード例 #3
0
 public override int GetHashCode()
 {
     unchecked
     {
         return((ConnectionId.GetHashCode() * 397) ^ IsLocalLoopback.GetHashCode());
     }
 }
コード例 #4
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (ClientIp.Length != 0)
            {
                hash ^= ClientIp.GetHashCode();
            }
            if (ClientPort != 0)
            {
                hash ^= ClientPort.GetHashCode();
            }
            if (Type.Length != 0)
            {
                hash ^= Type.GetHashCode();
            }
            if (ConnectionId.Length != 0)
            {
                hash ^= ConnectionId.GetHashCode();
            }
            if (ClientVersion.Length != 0)
            {
                hash ^= ClientVersion.GetHashCode();
            }
            hash ^= Labels.GetHashCode();
            hash ^= Headers.GetHashCode();
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
コード例 #5
0
 public override int GetHashCode()
 {
     unchecked
     {
         return((ConnectionId != null ? ConnectionId.GetHashCode() : 0) * 397);
     }
 }
コード例 #6
0
 public override int GetHashCode()
 {
     unchecked
     {
         return(((Ip != null ? Ip.GetHashCode() : 0) * 397) ^ ConnectionId.GetHashCode());
     }
 }
コード例 #7
0
        /// <summary>
        ///     Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            // credit: http://stackoverflow.com/a/263416/677735
            unchecked // Overflow is fine, just wrap
            {
                var hash = 41;
                // Suitable nullity checks etc, of course :)

                if (Op != null)
                {
                    hash = hash * 59 + Op.GetHashCode();
                }

                if (Id != null)
                {
                    hash = hash * 59 + Id.GetHashCode();
                }

                if (ConnectionId != null)
                {
                    hash = hash * 59 + ConnectionId.GetHashCode();
                }

                return(hash);
            }
        }
コード例 #8
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (ApplicationId != null ? ApplicationId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ ConnectionId.GetHashCode();
         hashCode = (hashCode * 397) ^ ApplicationInstanceId.GetHashCode();
         return(hashCode);
     }
 }
コード例 #9
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (ServiceId != null ? ServiceId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ ServiceAlias.GetHashCode();
         hashCode = (hashCode * 397) ^ (ApplicationId != null ? ApplicationId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ ConnectionId.GetHashCode();
         return(hashCode);
     }
 }
コード例 #10
0
ファイル: Message.cs プロジェクト: withakay/ably-dotnet
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (Id != null ? Id.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ClientId != null ? ClientId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ConnectionId != null ? ConnectionId.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ Timestamp.GetHashCode();
         hashCode = (hashCode * 397) ^ (Data != null ? Data.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Encoding != null ? Encoding.GetHashCode() : 0);
         return(hashCode);
     }
 }
コード例 #11
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (ConnectionId != 0)
            {
                hash ^= ConnectionId.GetHashCode();
            }
            if (Data.Length != 0)
            {
                hash ^= Data.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
コード例 #12
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (connectionId_ != null)
            {
                hash ^= ConnectionId.GetHashCode();
            }
            if (AppId.Length != 0)
            {
                hash ^= AppId.GetHashCode();
            }
            if (appInstanceId_ != null)
            {
                hash ^= AppInstanceId.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
コード例 #13
0
        private string GetCacheKey(object query, string selectorCacheKey, out string queryText)
        {
            if (query is CachedOrganizationRequest)
            {
                return(this.GetCacheKey((query as CachedOrganizationRequest).Request, selectorCacheKey, out queryText));
            }
            if (query is RetrieveSingleRequest)
            {
                return(this.GetCacheKey((query as RetrieveSingleRequest).Request, selectorCacheKey, out queryText));
            }
            if (query is FetchMultipleRequest)
            {
                return(this.GetCacheKey((query as FetchMultipleRequest).Request, selectorCacheKey, out queryText));
            }

            var sb = new StringBuilder(128);

            var text       = queryText = this.GetCacheKey(query) ?? Serialize(query);
            var connection = !string.IsNullOrWhiteSpace(ConnectionId)
                                ? ":ConnectionId={0}".FormatWith(QueryHashingEnabled ? ConnectionId.GetHashCode().ToString(CultureInfo.InvariantCulture) : ConnectionId)
                                : null;
            var code     = QueryHashingEnabled ? text.GetHashCode().ToString(CultureInfo.InvariantCulture) : text;
            var selector = !string.IsNullOrEmpty(selectorCacheKey)
                                ? ":Selector={0}".FormatWith(selectorCacheKey)
                                : null;

            return(sb.AppendFormat("{0}{1}:Query={2}{3}",
                                   GetType().FullName,
                                   connection,
                                   code,
                                   selector).ToString());
        }
コード例 #14
0
 public override int GetHashCode()
 {
     return(ConnectionId.GetHashCode());
 }
コード例 #15
0
        private string GetCacheKey(object query, string selectorCacheKey)
        {
            var text       = InternalGetCacheKey(query) ?? Serialize(query);
            var connection = !string.IsNullOrWhiteSpace(ConnectionId)
                                ? ":ConnectionId={0}".FormatWith(QueryHashingEnabled ? ConnectionId.GetHashCode().ToString(CultureInfo.InvariantCulture) : ConnectionId)
                                : null;
            var code     = QueryHashingEnabled ? text.GetHashCode().ToString(CultureInfo.InvariantCulture) : text;
            var selector = !string.IsNullOrEmpty(selectorCacheKey)
                                ? ":Selector={0}".FormatWith(selectorCacheKey)
                                : null;

            return("{0}{1}:Query={2}{3}".FormatWith(
                       GetType().FullName,
                       connection,
                       code,
                       selector));
        }
コード例 #16
0
 public override int GetHashCode()
 {
     return((ConnectionId.GetHashCode() + Username.GetHashCode()) / 2 + Convert.ToInt32(IsKicked));
 }