OSDN Git Service

C# 8.0 のnull許容参照型を有効化
[opentween/open-tween.git] / OpenTween / Api / TwitterApiStatus.cs
index adf488d..c26815f 100644 (file)
@@ -19,6 +19,8 @@
 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
 // Boston, MA 02110-1301, USA.
 
+#nullable enable
+
 using System;
 using System.Collections.Concurrent;
 using System.Collections.Generic;
@@ -38,13 +40,13 @@ namespace OpenTween.Api
     {
         public TwitterApiAccessLevel AccessLevel { get; set; }
         public EndpointLimits AccessLimit { get; }
-        public ApiLimit MediaUploadLimit { get; set; }
+        public ApiLimit? MediaUploadLimit { get; set; }
 
         public class AccessLimitUpdatedEventArgs : EventArgs
         {
-            public string EndpointName { get; }
+            public string? EndpointName { get; }
 
-            public AccessLimitUpdatedEventArgs(string endpointName)
+            public AccessLimitUpdatedEventArgs(string? endpointName)
                 => this.EndpointName = endpointName;
         }
         public event EventHandler<AccessLimitUpdatedEventArgs> AccessLimitUpdated;
@@ -59,7 +61,7 @@ namespace OpenTween.Api
             this.MediaUploadLimit = null;
         }
 
-        internal static ApiLimit ParseRateLimit(IDictionary<string, string> header, string prefix)
+        internal static ApiLimit? ParseRateLimit(IDictionary<string, string> header, string prefix)
         {
             var limitCount = (int?)ParseHeaderValue(header, prefix + "Limit");
             var limitRemain = (int?)ParseHeaderValue(header, prefix + "Remaining");
@@ -157,12 +159,16 @@ namespace OpenTween.Api
             public EndpointLimits(TwitterApiStatus owner)
                 => this.Owner = owner;
 
-            public ApiLimit this[string endpoint]
+            public ApiLimit? this[string endpoint]
             {
                 get => this.innerDict.TryGetValue(endpoint, out var limit) ? limit : null;
                 set
                 {
-                    this.innerDict[endpoint] = value;
+                    if (value == null)
+                        this.innerDict.TryRemove(endpoint, out var _);
+                    else
+                        this.innerDict[endpoint] = value;
+
                     this.Owner.OnAccessLimitUpdated(new AccessLimitUpdatedEventArgs(endpoint));
                 }
             }