Nullable: System.Runtime.InteropServices.CustomMarshalers/WindowsRuntime (#23930)
[platform/upstream/coreclr.git] / src / System.Private.CoreLib / src / System / Runtime / InteropServices / WindowsRuntime / EventRegistrationTokenTable.cs
index 0fb8895..a69a1a8 100644 (file)
@@ -2,9 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
-//
-
-using System;
+#nullable enable
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.Threading;
@@ -20,7 +18,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
         // Cached multicast delegate which will invoke all of the currently registered delegates.  This
         // will be accessed frequently in common coding paterns, so we don't want to calculate it repeatedly.
-        private volatile T m_invokeList;
+        private volatile T m_invokeList = null!; // TODO-NULLABLE-GENERIC
 
         public EventRegistrationTokenTable()
         {
@@ -47,7 +45,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                 {
                     // The value being set replaces any of the existing values
                     m_tokens.Clear();
-                    m_invokeList = null;
+                    m_invokeList = null!; // TODO-NULLABLE-GENERIC
 
                     if (value != null)
                     {
@@ -85,9 +83,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             m_tokens[token] = handler;
 
             // Update the current invocation list to include the newly added delegate
-            Delegate invokeList = (Delegate)(object)m_invokeList;
+            Delegate? invokeList = (Delegate?)(object?)m_invokeList;
             invokeList = MulticastDelegate.Combine(invokeList, (Delegate)(object)handler);
-            m_invokeList = (T)(object)invokeList;
+            m_invokeList = (T)(object?)invokeList!; // TODO-NULLABLE-GENERIC
 
             return token;
         }
@@ -236,19 +234,19 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                 m_tokens.Remove(token);
 
                 // Update the current invocation list to remove the delegate
-                Delegate invokeList = (Delegate)(object)m_invokeList;
-                invokeList = MulticastDelegate.Remove(invokeList, (Delegate)(object)handler);
-                m_invokeList = (T)(object)invokeList;
+                Delegate? invokeList = (Delegate?)(object?)m_invokeList;
+                invokeList = MulticastDelegate.Remove(invokeList, (Delegate?)(object?)handler);
+                m_invokeList = (T)(object?)invokeList!; // TODO-NULLABLE-GENERIC
             }
         }
 
-        public static EventRegistrationTokenTable<T> GetOrCreateEventRegistrationTokenTable(ref EventRegistrationTokenTable<T> refEventTable)
+        public static EventRegistrationTokenTable<T> GetOrCreateEventRegistrationTokenTable(ref EventRegistrationTokenTable<T>? refEventTable)
         {
             if (refEventTable == null)
             {
                 Interlocked.CompareExchange(ref refEventTable, new EventRegistrationTokenTable<T>(), null);
             }
-            return refEventTable;
+            return refEventTable!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
         }
     }
 }