OSDN Git Service

C# 8.0 のnull許容参照型を有効化
[opentween/open-tween.git] / OpenTween / ImageListViewItem.cs
index a006f15..0584095 100644 (file)
@@ -24,6 +24,8 @@
 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
 // Boston, MA 02110-1301, USA.
 
+#nullable enable
+
 using System;
 using System.Net.Http;
 using System.Runtime.Serialization;
@@ -35,8 +37,8 @@ namespace OpenTween
     [Serializable]
     public class ImageListViewItem : ListViewItem
     {
-        protected readonly ImageCache imageCache;
-        protected readonly string imageUrl;
+        protected readonly ImageCache? imageCache;
+        protected readonly string? imageUrl;
 
         /// <summary>
         /// 状態表示に使用するアイコンのインデックスを取得・設定する。
@@ -47,7 +49,7 @@ namespace OpenTween
         public int StateIndex { get; set; }
 
         private readonly WeakReference imageReference = new WeakReference(null);
-        private Task imageTask = null;
+        private Task? imageTask = null;
 
         public event EventHandler ImageDownloaded;
 
@@ -56,14 +58,14 @@ namespace OpenTween
         {
         }
 
-        public ImageListViewItem(string[] items, ImageCache imageCache, string imageUrl)
+        public ImageListViewItem(string[] items, ImageCache? imageCache, string? imageUrl)
             : base(items)
         {
             this.imageCache = imageCache;
             this.imageUrl = imageUrl;
             this.StateIndex = -1;
 
-            var image = imageCache?.TryGetFromCache(imageUrl);
+            var image = imageUrl != null ? imageCache?.TryGetFromCache(imageUrl) : null;
 
             if (image != null)
                 this.imageReference.Target = image;
@@ -86,7 +88,7 @@ namespace OpenTween
 
         private async Task GetImageAsyncInternal(bool force)
         {
-            if (string.IsNullOrEmpty(this.imageUrl))
+            if (string.IsNullOrEmpty(this.imageUrl) || this.imageCache == null)
                 return;
 
             if (!force && this.imageReference.Target != null)