Пример #1
0
        private static int GetDeepHashCode(System.Text.Json.JsonElement value)
        {
            int hash = 0;

            if (value.ValueKind == System.Text.Json.JsonValueKind.Array)
            {
                foreach (System.Text.Json.JsonElement child in value.EnumerateArray())
                {
                    hash ^= ParsePerfTests.GetDeepHashCode(child);
                }
            }
            else if (value.ValueKind == System.Text.Json.JsonValueKind.Object)
            {
                foreach (System.Text.Json.JsonProperty pair in value.EnumerateObject())
                {
                    hash ^= ParsePerfTests.GetDeepHashCode(pair.Value);
                }
            }
            else if (value.ValueKind == System.Text.Json.JsonValueKind.False ||
                     value.ValueKind == System.Text.Json.JsonValueKind.True)
            {
                hash = value.GetBoolean().GetHashCode();
            }
            else if (value.ValueKind == System.Text.Json.JsonValueKind.String)
            {
                hash = value.GetString().GetHashCode();
            }
            else if (value.ValueKind == System.Text.Json.JsonValueKind.Number)
            {
                hash = value.GetDecimal().GetHashCode();
            }

            return(hash);
        }