refactor: clean code

This commit is contained in:
Fu Diwei
2021-12-15 15:39:43 +08:00
parent 4b46fa580d
commit f51c2e2be2
6 changed files with 20 additions and 19 deletions

View File

@@ -123,8 +123,8 @@ namespace SKIT.FlurlHttpClient.Wechat.Ads
{
byte[] bytes = await flurlResponse.GetBytesAsync().ConfigureAwait(false);
bool jsonable =
(bytes.Length > 1 && bytes[0] == 91 && bytes[bytes.Length - 1] == 93) || // "[...]"
(bytes.Length > 1 && bytes[0] == 123 && bytes[bytes.Length - 1] == 125); // "{...}"
(bytes.FirstOrDefault() == 91 && bytes.LastOrDefault() == 93) || // "[...]"
(bytes.FirstOrDefault() == 123 && bytes.LastOrDefault() == 125); // "{...}"
T result = jsonable ? JsonSerializer.Deserialize<T>(Encoding.UTF8.GetString(bytes)) : new T();