Ejemplo n.º 1
0
        /// <summary>
        /// Gets a hash code for the current instance.
        /// </summary>
        /// <returns>A hash code.</returns>
        /// <remarks>The hash code is based on the uppercase, invariant hash of the
        /// <see cref="ToString()">text representation</see> of the object.</remarks>
        public override int GetHashCode()
        {
            var hashes = new List <int>(4);

            if (GroupVersion != null)
            {
                hashes.Add(GroupVersion.Value.GetHashCode());
            }

            if (MajorVersion != null)
            {
                hashes.Add(MajorVersion.Value.GetHashCode());
                hashes.Add(ImpliedMinorVersion.GetHashCode());
            }

            if (!IsNullOrEmpty(Status))
            {
                hashes.Add(StringComparer.OrdinalIgnoreCase.GetHashCode(Status));
            }

            var hash = hashes[0];

            for (var i = 1; i < hashes.Count; i++)
            {
                hash = (hash * 397) ^ hashes[i];
            }

            return(hash);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets a hash code for the current instance.
        /// </summary>
        /// <returns>A hash code.</returns>
        /// <remarks>The hash code is based on the uppercase, invariant hash of the
        /// <see cref="ToString()">text representation</see> of the object.</remarks>
        public override int GetHashCode()
        {
            // perf: api version is used in a lot sets and as a dictionary keys
            // since it's immutable, calculate the hash code once and reuse it
            if (hashCode != default)
            {
                return(hashCode);
            }

            var hashes = new List <int>(capacity: 4);

            if (GroupVersion != null)
            {
                hashes.Add(GroupVersion.Value.GetHashCode());
            }

            if (MajorVersion != null)
            {
                hashes.Add(MajorVersion.Value.GetHashCode());
                hashes.Add(ImpliedMinorVersion.GetHashCode());
            }

            if (!IsNullOrEmpty(Status))
            {
                hashes.Add(StringComparer.OrdinalIgnoreCase.GetHashCode(Status));
            }

            var hash = hashes[0];

            for (var i = 1; i < hashes.Count; i++)
            {
                hash = (hash * Prime) ^ hashes[i];
            }

            return(hashCode = hash);
        }