OSDN Git Service

OpenTween v2.4.2 リリース
[opentween/open-tween.git] / OpenTween / Connection / LazyJson.cs
index 07bab5a..6bcca45 100644 (file)
 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
 // Boston, MA 02110-1301, USA.
 
+#nullable enable annotations
+
 using System;
 using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
 using System.Linq;
 using System.Net.Http;
 using System.Runtime.Serialization;
@@ -35,15 +38,13 @@ namespace OpenTween.Connection
     /// </summary>
     public sealed class LazyJson<T> : IDisposable
     {
-        public HttpResponseMessage Response { get; }
+        public HttpResponseMessage? Response { get; }
 
         private T instance;
         private bool completed = false;
 
         public LazyJson(HttpResponseMessage response)
-        {
-            this.Response = response;
-        }
+            => this.Response = response;
 
         internal LazyJson(T instance)
         {
@@ -56,31 +57,27 @@ namespace OpenTween.Connection
         public async Task<T> LoadJsonAsync()
         {
             if (this.completed)
-                return this.instance;
+                return this.instance!;
 
-            using (var content = this.Response.Content)
-            {
-                var responseText = await content.ReadAsStringAsync()
-                    .ConfigureAwait(false);
+            using var content = this.Response.Content;
+            var responseText = await content.ReadAsStringAsync()
+                .ConfigureAwait(false);
 
-                try
-                {
-                    this.instance = MyCommon.CreateDataFromJson<T>(responseText);
-                    this.completed = true;
+            try
+            {
+                this.instance = MyCommon.CreateDataFromJson<T>(responseText);
+                this.completed = true;
 
-                    return this.instance;
-                }
-                catch (SerializationException ex)
-                {
-                    throw TwitterApiException.CreateFromException(ex, responseText);
-                }
+                return this.instance;
+            }
+            catch (SerializationException ex)
+            {
+                throw TwitterApiException.CreateFromException(ex, responseText);
             }
         }
 
         public void Dispose()
-        {
-            this.Response?.Dispose();
-        }
+            => this.Response?.Dispose();
     }
 
     public static class LazyJson
@@ -93,10 +90,8 @@ namespace OpenTween.Connection
     {
         public static async Task IgnoreResponse<T>(this Task<LazyJson<T>> task)
         {
-            using (var lazyJson = await task.ConfigureAwait(false))
-            {
-                // レスポンスボディを読み込まず破棄する
-            }
+            using var lazyJson = await task.ConfigureAwait(false);
+            // レスポンスボディを読み込まず破棄する
         }
     }
 }