コード例 #1
0
        /// <inheritdoc/>
        public override int GetHashCode()
        {
            switch (Type)
            {
            case LdValueType.Null:
                return(0);

            case LdValueType.Bool:
                return(AsBool.GetHashCode());

            case LdValueType.Number:
                return(AsFloat.GetHashCode());

            case LdValueType.String:
                return(AsString.GetHashCode());

            case LdValueType.Array:
            {
                var h = new HashCodeBuilder();
                foreach (var item in AsList(Convert.Json))
                {
                    h = h.With(item);
                }
                return(h.Value);
            }

            case LdValueType.Object:
            {
                var h    = new HashCodeBuilder();
                var d    = AsDictionary(Convert.Json);
                var keys = d.Keys.ToArray();
                Array.Sort(keys);         // inefficient, but ensures determinacy
                foreach (var key in keys)
                {
                    h = h.With(key).With(d[key]);
                }
                return(h.Value);
            }

            default:
                return(0);
            }
        }