Exemplo n.º 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);
        }
Exemplo n.º 2
0
        private static T?ToObject <T>(this System.Text.Json.JsonElement element) where T : OAuthUser
        {
            var user   = new OAuthUser();
            var target = element.EnumerateObject();

            user.Id         = target.TryGetValue("Id");
            user.Login      = target.TryGetValue("Login");
            user.Name       = target.TryGetValue("Name");
            user.Avatar_Url = target.TryGetValue("Avatar_Url");
            return(user as T);
        }
Exemplo n.º 3
0
        private static T ToObject <T>(this System.Text.Json.JsonElement element) where T : WeChatUser
        {
            var user   = new WeChatUser();
            var target = element.EnumerateObject();

            user.OpenId     = target.TryGetValue("OpenId");
            user.UnionId    = target.TryGetValue("UnionId");
            user.NickName   = target.TryGetValue("NickName");
            user.Privilege  = target.TryGetValue("Privilege");
            user.Sex        = target.TryGetValue("Sex");
            user.Province   = target.TryGetValue("Province");
            user.City       = target.TryGetValue("City");
            user.Country    = target.TryGetValue("Country");
            user.HeadImgUrl = target.TryGetValue("HeadImgUrl");
            user.Privilege  = target.TryGetValue("Privilege");
            return(user as T);
        }