Nullable: System.Runtime.InteropServices.CustomMarshalers/WindowsRuntime (#23930)
authorStephen Toub <stoub@microsoft.com>
Mon, 15 Apr 2019 01:29:22 +0000 (21:29 -0400)
committerGitHub <noreply@github.com>
Mon, 15 Apr 2019 01:29:22 +0000 (21:29 -0400)
51 files changed:
src/System.Private.CoreLib/shared/System/Runtime/InteropServices/ICustomMarshaler.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/ComTypes/IEnumerable.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/EnumVariantViewOfEnumerator.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/EnumerableToDispatchMarshaler.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/EnumerableViewOfDispatch.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/EnumeratorToEnumVariantMarshaler.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/EnumeratorViewOfEnumVariant.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/ExpandoToDispatchExMarshaler.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/TypeToTypeInfoMarshaler.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToCollectionAdapter.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToListAdapter.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CustomPropertyImpl.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryToMapAdapter.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/EnumeratorToIteratorAdapter.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationTokenTable.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IActivationFactory.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IClosable.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomProperty.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomPropertyProvider.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IIterable.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IIterator.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IMap.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IPropertyValue.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyDictionaryToIMapViewAdapter.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyListToIVectorViewAdapter.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IReference.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IRestrictedErrorInfo.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IVector.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IVectorViewToIReadOnlyListAdapter.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IteratorToEnumeratorAdapter.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorViewAdapter.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ListToVectorAdapter.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ManagedActivationFactory.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/MapToCollectionAdapter.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/MapViewToReadOnlyCollectionAdapter.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/NativeMethods.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/PropertyValue.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/RuntimeClass.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToCollectionAdapter.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToListAdapter.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/VectorViewToReadOnlyCollectionAdapter.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsFoundationEventHandler.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMarshal.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMetadata.cs

index cf442d4..6a5f5d8 100644 (file)
@@ -2,6 +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.
 
+#nullable enable
 namespace System.Runtime.InteropServices
 {
     // This the base interface that must be implemented by all custom marshalers.
index e541960..68efabc 100644 (file)
@@ -2,7 +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
 namespace System.Runtime.InteropServices.ComTypes
 {
     /*==========================================================================
index d43b682..670aea6 100644 (file)
@@ -2,7 +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;
 using System.Runtime.InteropServices.ComTypes;
 
@@ -34,7 +34,7 @@ namespace System.Runtime.InteropServices.CustomMarshalers
             }
         }
 
-        public int Next(int celt, object[] rgVar, IntPtr pceltFetched)
+        public int Next(int celt, object?[] rgVar, IntPtr pceltFetched)
         {
             int numElements = 0;
 
index 332a885..93058a3 100644 (file)
@@ -11,7 +11,7 @@ namespace System.Runtime.InteropServices.CustomMarshalers
     {
         private static readonly EnumerableToDispatchMarshaler s_enumerableToDispatchMarshaler = new EnumerableToDispatchMarshaler();
 
-        public static ICustomMarshaler GetInstance(string cookie) => s_enumerableToDispatchMarshaler;
+        public static ICustomMarshaler GetInstance(string? cookie) => s_enumerableToDispatchMarshaler;
 
         private EnumerableToDispatchMarshaler()
         {
index 67bb393..2988332 100644 (file)
@@ -2,11 +2,10 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 using System.Collections;
 using System.Runtime.InteropServices.ComTypes;
 
-using Variant = System.Runtime.InteropServices.Variant;
-
 namespace System.Runtime.InteropServices.CustomMarshalers
 {
     internal class EnumerableViewOfDispatch : ICustomAdapter, System.Collections.IEnumerable
@@ -42,7 +41,7 @@ namespace System.Runtime.InteropServices.CustomMarshalers
                     IntPtr.Zero);
             }
 
-            object resultAsObject = result.ToObject();
+            object? resultAsObject = result.ToObject();
             if (!(resultAsObject is IEnumVARIANT enumVariant))
             {
                 throw new InvalidOperationException(SR.InvalidOp_InvalidNewEnumVariant);
index fddc0c7..6e5e7b1 100644 (file)
@@ -2,11 +2,9 @@
 // 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;
-using System.Collections.Generic;
 using System.Runtime.InteropServices.ComTypes;
-using System.Text;
 
 namespace System.Runtime.InteropServices.CustomMarshalers
 {
@@ -14,7 +12,7 @@ namespace System.Runtime.InteropServices.CustomMarshalers
     {
         private static readonly EnumeratorToEnumVariantMarshaler s_enumeratorToEnumVariantMarshaler = new EnumeratorToEnumVariantMarshaler();
 
-        public static ICustomMarshaler GetInstance(string cookie) => s_enumeratorToEnumVariantMarshaler;
+        public static ICustomMarshaler GetInstance(string? cookie) => s_enumeratorToEnumVariantMarshaler;
 
         private EnumeratorToEnumVariantMarshaler()
         {
@@ -68,7 +66,7 @@ namespace System.Runtime.InteropServices.CustomMarshalers
                     return enumVariantView.Enumerator;
                 }
 
-                return comObject as IEnumerator;
+                return (comObject as IEnumerator)!;
             }
 
             return ComDataHelpers.GetOrCreateManagedViewFromComData<IEnumVARIANT, EnumeratorViewOfEnumVariant>(comObject, var => new EnumeratorViewOfEnumVariant(var));
index b5ef969..bb2839d 100644 (file)
@@ -2,11 +2,9 @@
 // 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;
-using System.Collections.Generic;
 using System.Runtime.InteropServices.ComTypes;
-using System.Text;
 
 namespace System.Runtime.InteropServices.CustomMarshalers
 {
@@ -15,7 +13,7 @@ namespace System.Runtime.InteropServices.CustomMarshalers
         private readonly IEnumVARIANT _enumVariantObject;
         private bool _fetchedLastObject;
         private object[] _nextArray = new object[1];
-        private object _current;
+        private object? _current;
 
         public EnumeratorViewOfEnumVariant(IEnumVARIANT enumVariantObject)
         {
@@ -24,7 +22,7 @@ namespace System.Runtime.InteropServices.CustomMarshalers
             _current = null;
         }
 
-        public object Current => _current;
+        public object? Current => _current; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/23268
 
         public unsafe bool MoveNext()
         {
index 3cd8292..30b55cc 100644 (file)
@@ -2,19 +2,14 @@
 // 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;
-using System.Collections;
-using System.Collections.Generic;
-using System.Runtime.InteropServices.ComTypes;
-using System.Text;
-
+#nullable enable
 namespace System.Runtime.InteropServices.CustomMarshalers
 {
     internal class ExpandoToDispatchExMarshaler : ICustomMarshaler
     {
         private static readonly ExpandoToDispatchExMarshaler s_ExpandoToDispatchExMarshaler = new ExpandoToDispatchExMarshaler();
 
-        public static ICustomMarshaler GetInstance(string cookie) => s_ExpandoToDispatchExMarshaler;
+        public static ICustomMarshaler GetInstance(string? cookie) => s_ExpandoToDispatchExMarshaler;
 
         private ExpandoToDispatchExMarshaler()
         {
index eeae079..eda7c85 100644 (file)
@@ -2,19 +2,14 @@
 // 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;
-using System.Collections;
-using System.Collections.Generic;
-using System.Runtime.InteropServices.ComTypes;
-using System.Text;
-
+#nullable enable
 namespace System.Runtime.InteropServices.CustomMarshalers
 {
     internal class TypeToTypeInfoMarshaler : ICustomMarshaler
     {
         private static readonly TypeToTypeInfoMarshaler s_typeToTypeInfoMarshaler = new TypeToTypeInfoMarshaler();
 
-        public static ICustomMarshaler GetInstance(string cookie) => s_typeToTypeInfoMarshaler;
+        public static ICustomMarshaler GetInstance(string? cookie) => s_typeToTypeInfoMarshaler;
 
         private TypeToTypeInfoMarshaler()
         {
index ce4be34..201e23b 100644 (file)
@@ -2,16 +2,8 @@
 // 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;
-using System.Runtime;
-using System.Security;
-using System.Collections;
-using System.Collections.Generic;
+#nullable enable
 using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
index 6542f5c..5ac54b7 100644 (file)
@@ -2,16 +2,8 @@
 // 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;
-using System.Runtime;
-using System.Security;
-using System.Collections;
-using System.Collections.Generic;
+#nullable enable
 using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
@@ -32,7 +24,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         }
 
         // object this[int index] { get }
-        internal object Indexer_Get(int index)
+        internal object? Indexer_Get(int index)
         {
             if (index < 0)
                 throw new ArgumentOutOfRangeException(nameof(index));
@@ -154,7 +146,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
         // Helpers:
 
-        private static object GetAt(IBindableVector _this, uint index)
+        private static object? GetAt(IBindableVector _this, uint index)
         {
             try
             {
index 92c78f9..2575794 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;
 
index a21d6a0..8a3ed8a 100644 (file)
@@ -2,13 +2,10 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+#nullable enable
 using System.Diagnostics;
 using System.Collections;
 using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Diagnostics.Contracts;
-using System.Runtime.InteropServices;
-
 
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
@@ -100,6 +97,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
             if (!found)
             {
+                Debug.Assert(key != null);
                 Exception e = new KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
                 e.HResult = HResults.E_BOUNDS;
                 throw e;
@@ -131,7 +129,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             return new IKeyValuePairEnumerator(items, firstItemIndex, lastItemIndex);
         }
 
-        public void Split(out IMapView<TKey, TValue> firstPartition, out IMapView<TKey, TValue> secondPartition)
+        public void Split(out IMapView<TKey, TValue>? firstPartition, out IMapView<TKey, TValue>? secondPartition)
         {
             if (Count < 2)
             {
@@ -150,12 +148,12 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
         public bool TryGetValue(TKey key, out TValue value)
         {
-            KeyValuePair<TKey, TValue> searchKey = new KeyValuePair<TKey, TValue>(key, default);
+            KeyValuePair<TKey, TValue> searchKey = new KeyValuePair<TKey, TValue>(key, default!); // TODO-NULLABLE-GENERIC
             int index = Array.BinarySearch(items, firstItemIndex, Count, searchKey, keyValuePairComparator);
 
             if (index < 0)
             {
-                value = default;
+                value = default!; // TODO-NULLABLE-GENERIC
                 return false;
             }
 
@@ -208,7 +206,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                 }
             }
 
-            object IEnumerator.Current
+            object? IEnumerator.Current // TODO-NULLABLE: 
             {
                 get
                 {
index 6874148..10d663b 100644 (file)
@@ -2,17 +2,8 @@
 // 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;
-using System.Security;
+#nullable enable
 using System.Reflection;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-using System.Runtime.Serialization;
-using System.StubHelpers;
-using System.Globalization;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
@@ -88,7 +79,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             InvokeInternal(target, new object[] { indexValue, value }, false);
         }
 
-        private object InvokeInternal(object target, object[] args, bool getValue)
+        private object InvokeInternal(object target, object[]? args, bool getValue)
         {
             // Forward to the right object if we are dealing with a proxy
             if (target is IGetProxyTarget proxy)
@@ -114,7 +105,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                         accessor,
                         accessor.DeclaringType.FullName));
 
-            RuntimeMethodInfo rtMethod = accessor as RuntimeMethodInfo;
+            RuntimeMethodInfo? rtMethod = accessor as RuntimeMethodInfo;
             if (rtMethod == null)
                 throw new ArgumentException(SR.Argument_MustBeRuntimeMethodInfo);
 
index 2751209..70e046d 100644 (file)
@@ -2,7 +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;
 using System.Collections.Generic;
 using System.Diagnostics;
@@ -106,7 +106,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             return enumeration.MoveNext();
         }
 
-        object IEnumerator.Current
+        object? IEnumerator.Current
         {
             get { return ((IEnumerator<TKey>)this).Current; }
         }
index 53a889e..b78fef6 100644 (file)
@@ -2,17 +2,10 @@
 // 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;
-using System.Security;
-using System.Reflection;
-using System.Collections;
+#nullable enable
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
@@ -41,6 +34,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
             if (!keyFound)
             {
+                Debug.Assert(key != null);
                 Exception e = new KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
                 e.HResult = HResults.E_BOUNDS;
                 throw e;
@@ -95,6 +89,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
             if (!removed)
             {
+                Debug.Assert(key != null);
                 Exception e = new KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
                 e.HResult = HResults.E_BOUNDS;
                 throw e;
index b1d9c8c..eb85161 100644 (file)
@@ -2,13 +2,10 @@
 // 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;
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.InteropServices.WindowsRuntime;
-
 
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
@@ -113,7 +110,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             return enumeration.MoveNext();
         }
 
-        object IEnumerator.Current
+        object? IEnumerator.Current
         {
             get { return ((IEnumerator<TValue>)this).Current; }
         }
index 5299af3..bde80a9 100644 (file)
@@ -2,14 +2,10 @@
 // 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;
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
@@ -44,14 +40,14 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             Debug.Fail("This class is never instantiated");
         }
 
-        internal sealed class NonGenericToGenericEnumerator : IEnumerator<object>
+        internal sealed class NonGenericToGenericEnumerator : IEnumerator<object?>
         {
             private IEnumerator enumerator;
 
             public NonGenericToGenericEnumerator(IEnumerator enumerator)
             { this.enumerator = enumerator; }
 
-            public object Current { get { return enumerator.Current; } }
+            public object? Current { get { return enumerator.Current; } }
             public bool MoveNext() { return enumerator.MoveNext(); }
             public void Reset() { enumerator.Reset(); }
             public void Dispose() { }
@@ -61,7 +57,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         internal IBindableIterator First_Stub()
         {
             IEnumerable _this = Unsafe.As<IEnumerable>(this);
-            return new EnumeratorToIteratorAdapter<object>(new NonGenericToGenericEnumerator(_this.GetEnumerator()));
+            return new EnumeratorToIteratorAdapter<object?>(new NonGenericToGenericEnumerator(_this.GetEnumerator()));
         }
     }
 
@@ -99,11 +95,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             }
         }
 
-        object IBindableIterator.Current
+        object? IBindableIterator.Current
         {
             get
             {
-                return (object)((IIterator<T>)this).Current;
+                return ((IIterator<T>)this).Current;
             }
         }
 
@@ -154,7 +150,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
             if (typeof(T) == typeof(string))
             {
-                string[] stringItems = items as string[];
+                string[] stringItems = (items as string[])!;
 
                 // Fill the rest of the array with string.Empty to avoid marshaling failure
                 for (int i = index; i < items.Length; ++i)
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
         }
     }
 }
index 0ce01f8..578d219 100644 (file)
@@ -2,11 +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;
-using System.Runtime.InteropServices;
-
+#nullable enable
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
     [ComImport]
index 7891fd4..8b85d5c 100644 (file)
@@ -2,13 +2,8 @@
 // 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;
-using System.Security;
-using System.Collections;
+#nullable enable
 using System.Diagnostics;
-using System.Runtime.CompilerServices;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
index 07fb8f1..30075cc 100644 (file)
@@ -2,10 +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
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
     [ComImport]
index 56cc2f6..78d399b 100644 (file)
@@ -2,17 +2,12 @@
 // 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.StubHelpers;
 using System.Reflection;
 using System.Diagnostics;
-using System.Runtime.InteropServices;
 using System.Collections;
 using System.Collections.Generic;
-using System.Runtime.CompilerServices;
-using System.Security;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
@@ -26,7 +21,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         // Creates a ICustomProperty implementation for Jupiter
         // Called from ICustomPropertyProvider_GetProperty from within runtime
         //
-        internal static ICustomProperty CreateProperty(object target, string propertyName)
+        internal static ICustomProperty? CreateProperty(object target, string propertyName)
         {
             Debug.Assert(target != null);
             Debug.Assert(propertyName != null);
@@ -49,18 +44,18 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         // Creates a ICustomProperty implementation for Jupiter
         // Called from ICustomPropertyProvider_GetIndexedProperty from within runtime
         //               
-        internal static unsafe ICustomProperty CreateIndexedProperty(object target, string propertyName, TypeNameNative* pIndexedParamType)
+        internal static unsafe ICustomProperty? CreateIndexedProperty(object target, string propertyName, TypeNameNative* pIndexedParamType)
         {
             Debug.Assert(target != null);
             Debug.Assert(propertyName != null);
 
-            Type indexedParamType = null;
+            Type? indexedParamType = null;
             SystemTypeMarshaler.ConvertToManaged(pIndexedParamType, ref indexedParamType);
 
             return CreateIndexedProperty(target, propertyName, indexedParamType);
         }
 
-        internal static ICustomProperty CreateIndexedProperty(object target, string propertyName, Type indexedParamType)
+        internal static ICustomProperty? CreateIndexedProperty(object target, string propertyName, Type? indexedParamType)
         {
             Debug.Assert(target != null);
             Debug.Assert(propertyName != null);
@@ -74,7 +69,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                 BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public,
                 null,                                                                   // default binder
                 null,                                                                   // ignore return type
-                new Type[] { indexedParamType },                                        // indexed parameter type
+                new Type?[] { indexedParamType },                                        // indexed parameter type
                 null                                                                    // ignore type modifier
                 );
 
@@ -186,7 +181,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         //
         // override ToString() to make sure callers get correct IStringable.ToString() behavior in native code
         //
-        public override string ToString()
+        public override string? ToString()
         {
             return WindowsRuntime.IStringableHelper.ToString(_target);
         }
@@ -241,9 +236,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         //
         // IBindableVector implementation (forwards to IBindableVector / IVector<T>)
         //        
-        object IBindableVector.GetAt(uint index)
+        object? IBindableVector.GetAt(uint index)
         {
-            IBindableVector bindableVector = GetIBindableVectorNoThrow();
+            IBindableVector? bindableVector = GetIBindableVectorNoThrow();
             if (bindableVector != null)
             {
                 // IBindableVector -> IBindableVector
@@ -260,7 +255,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         {
             get
             {
-                IBindableVector bindableVector = GetIBindableVectorNoThrow();
+                IBindableVector? bindableVector = GetIBindableVectorNoThrow();
                 if (bindableVector != null)
                 {
                     // IBindableVector -> IBindableVector
@@ -276,7 +271,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
         IBindableVectorView IBindableVector.GetView()
         {
-            IBindableVector bindableVector = GetIBindableVectorNoThrow();
+            IBindableVector? bindableVector = GetIBindableVectorNoThrow();
             if (bindableVector != null)
             {
                 // IBindableVector -> IBindableVector
@@ -298,7 +293,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                 _vectorView = vectorView;
             }
 
-            object IBindableVectorView.GetAt(uint index)
+            object? IBindableVectorView.GetAt(uint index)
             {
                 return _vectorView.GetAt(index);
             }
@@ -324,7 +319,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
         bool IBindableVector.IndexOf(object value, out uint index)
         {
-            IBindableVector bindableVector = GetIBindableVectorNoThrow();
+            IBindableVector? bindableVector = GetIBindableVectorNoThrow();
             if (bindableVector != null)
             {
                 // IBindableVector -> IBindableVector
@@ -339,7 +334,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
         void IBindableVector.SetAt(uint index, object value)
         {
-            IBindableVector bindableVector = GetIBindableVectorNoThrow();
+            IBindableVector? bindableVector = GetIBindableVectorNoThrow();
             if (bindableVector != null)
             {
                 // IBindableVector -> IBindableVector
@@ -354,7 +349,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
         void IBindableVector.InsertAt(uint index, object value)
         {
-            IBindableVector bindableVector = GetIBindableVectorNoThrow();
+            IBindableVector? bindableVector = GetIBindableVectorNoThrow();
             if (bindableVector != null)
             {
                 // IBindableVector -> IBindableVector
@@ -369,7 +364,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
         void IBindableVector.RemoveAt(uint index)
         {
-            IBindableVector bindableVector = GetIBindableVectorNoThrow();
+            IBindableVector? bindableVector = GetIBindableVectorNoThrow();
             if (bindableVector != null)
             {
                 // IBindableVector -> IBindableVector
@@ -384,7 +379,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
         void IBindableVector.Append(object value)
         {
-            IBindableVector bindableVector = GetIBindableVectorNoThrow();
+            IBindableVector? bindableVector = GetIBindableVectorNoThrow();
             if (bindableVector != null)
             {
                 // IBindableVector -> IBindableVector
@@ -399,7 +394,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
         void IBindableVector.RemoveAtEnd()
         {
-            IBindableVector bindableVector = GetIBindableVectorNoThrow();
+            IBindableVector? bindableVector = GetIBindableVectorNoThrow();
             if (bindableVector != null)
             {
                 // IBindableVector -> IBindableVector
@@ -414,7 +409,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
         void IBindableVector.Clear()
         {
-            IBindableVector bindableVector = GetIBindableVectorNoThrow();
+            IBindableVector? bindableVector = GetIBindableVectorNoThrow();
             if (bindableVector != null)
             {
                 // IBindableVector -> IBindableVector
@@ -427,7 +422,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             }
         }
 
-        private IBindableVector GetIBindableVectorNoThrow()
+        private IBindableVector? GetIBindableVectorNoThrow()
         {
             if ((_flags & InterfaceForwardingSupport.IBindableVector) != 0)
                 return Unsafe.As<IBindableVector>(_target);
@@ -447,9 +442,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         //
         // IBindableVectorView implementation (forwarding to IBindableVectorView or IVectorView<T>)
         //
-        object IBindableVectorView.GetAt(uint index)
+        object? IBindableVectorView.GetAt(uint index)
         {
-            IBindableVectorView bindableVectorView = GetIBindableVectorViewNoThrow();
+            IBindableVectorView? bindableVectorView = GetIBindableVectorViewNoThrow();
             if (bindableVectorView != null)
                 return bindableVectorView.GetAt(index);
             else
@@ -460,7 +455,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         {
             get
             {
-                IBindableVectorView bindableVectorView = GetIBindableVectorViewNoThrow();
+                IBindableVectorView? bindableVectorView = GetIBindableVectorViewNoThrow();
                 if (bindableVectorView != null)
                     return bindableVectorView.Size;
                 else
@@ -470,7 +465,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
         bool IBindableVectorView.IndexOf(object value, out uint index)
         {
-            IBindableVectorView bindableVectorView = GetIBindableVectorViewNoThrow();
+            IBindableVectorView? bindableVectorView = GetIBindableVectorViewNoThrow();
             if (bindableVectorView != null)
                 return bindableVectorView.IndexOf(value, out index);
             else
@@ -479,7 +474,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
         IBindableIterator IBindableIterable.First()
         {
-            IBindableVectorView bindableVectorView = GetIBindableVectorViewNoThrow();
+            IBindableVectorView? bindableVectorView = GetIBindableVectorViewNoThrow();
             if (bindableVectorView != null)
                 return bindableVectorView.First();
             else
@@ -494,11 +489,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             { _iterator = iterator; }
 
             public bool HasCurrent { get { return _iterator.HasCurrent; } }
-            public object Current { get { return (object)_iterator.Current; } }
+            public object? Current { get { return _iterator.Current; } }
             public bool MoveNext() { return _iterator.MoveNext(); }
         }
 
-        private IBindableVectorView GetIBindableVectorViewNoThrow()
+        private IBindableVectorView? GetIBindableVectorViewNoThrow()
         {
             if ((_flags & InterfaceForwardingSupport.IBindableVectorView) != 0)
                 return Unsafe.As<IBindableVectorView>(_target);
index a445912..94a00d3 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;
 
 // Windows.Foundation.Collections.IIterable`1 cannot be referenced from managed code because it's hidden
index 00d622b..27ebdfb 100644 (file)
@@ -2,10 +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
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
     [ComImport]
@@ -33,7 +30,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
     [Guid("6a1d6c07-076d-49f2-8314-f52c9c9a8331")]
     internal interface IBindableIterator
     {
-        object Current
+        object? Current
         {
             get;
         }
index 02dff54..0f684be 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;
 
 // Windows.Foundation.Collections.IMap`2, IMapView`2, and IKeyValuePair`2 cannot be referenced from
@@ -35,7 +33,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         V Lookup(K key);
         uint Size { get; }
         bool HasKey(K key);
-        void Split(out IMapView<K, V> first, out IMapView<K, V> second);
+        void Split(out IMapView<K, V>? first, out IMapView<K, V>? second);
     }
 
     [ComImport]
index 3a80860..d81cb6c 100644 (file)
@@ -2,15 +2,10 @@
 // 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;
-using System.Security;
+#nullable enable
 using System.Collections;
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
@@ -79,7 +74,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             // throw an exception from Lookup.
             if (!_this.HasKey(key))
             {
-                value = default;
+                value = default!; // TODO-NULLABLE-GENERIC
                 return false;
             }
 
@@ -92,7 +87,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             {
                 if (HResults.E_BOUNDS == ex.HResult)
                 {
-                    value = default;
+                    value = default!; // TODO-NULLABLE-GENERIC
                     return false;
                 }
                 throw;
@@ -199,7 +194,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             return enumeration.MoveNext();
         }
 
-        object IEnumerator.Current
+        object? IEnumerator.Current
         {
             get { return ((IEnumerator<TKey>)this).Current; }
         }
@@ -298,7 +293,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             return enumeration.MoveNext();
         }
 
-        object IEnumerator.Current
+        object? IEnumerator.Current
         {
             get { return ((IEnumerator<TValue>)this).Current; }
         }
index aefa7be..5ad32ea 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
 
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
index 01e8f7b..0e80f0a 100644 (file)
@@ -2,15 +2,9 @@
 // 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;
-using System.Security;
-using System.Collections;
+#nullable enable
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
@@ -40,6 +34,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
             if (!keyFound)
             {
+                Debug.Assert(key != null);
                 Exception e = new KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString()));
                 e.HResult = HResults.E_BOUNDS;
                 throw e;
@@ -63,7 +58,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         }
 
         // void Split(out IMapView<K, V> first, out IMapView<K, V> second)
-        internal void Split<K, V>(out IMapView<K, V> first, out IMapView<K, V> second)
+        internal void Split<K, V>(out IMapView<K, V>? first, out IMapView<K, V>? second)
         {
             IReadOnlyDictionary<K, V> _this = Unsafe.As<IReadOnlyDictionary<K, V>>(this);
 
index 6269f2e..d608a8a 100644 (file)
@@ -2,15 +2,9 @@
 // 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;
-using System.Security;
-using System.Collections;
+#nullable enable
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
@@ -108,7 +102,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
             if (typeof(T) == typeof(string))
             {
-                string[] stringItems = items as string[];
+                string[] stringItems = (items as string[])!;
 
                 // Fill in the rest of the array with string.Empty to avoid marshaling failure
                 for (uint i = itemCount; i < items.Length; ++i)
index d0101da..844f866 100644 (file)
@@ -2,10 +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
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
     [ComImport]
index 03faef0..db8dc38 100644 (file)
@@ -2,10 +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
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
     [ComImport]
index f00a7d3..7087239 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;
 
 // Windows.Foundation.Collections.IVector`1 and IVectorView`1 cannot be referenced from managed
@@ -66,7 +64,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
     [WindowsRuntimeImport]
     internal interface IBindableVector : IBindableIterable
     {
-        object GetAt(uint index);
+        object? GetAt(uint index);
         uint Size { get; }
         IBindableVectorView GetView();
         bool IndexOf(object value, out uint index);
@@ -83,7 +81,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
     [WindowsRuntimeImport]
     internal interface IBindableVectorView : IBindableIterable
     {
-        object GetAt(uint index);
+        object? GetAt(uint index);
         uint Size { get; }
         bool IndexOf(object value, out uint index);
     }
index f6667ac..0bc7d04 100644 (file)
@@ -2,15 +2,9 @@
 // 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;
-using System.Security;
-using System.Collections;
+#nullable enable
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
index d49836c..ad8ec67 100644 (file)
@@ -2,15 +2,10 @@
 // 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;
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-using System.Security;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
@@ -72,24 +67,24 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             Debug.Fail("This class is never instantiated");
         }
 
-        private sealed class NonGenericToGenericIterator : IIterator<object>
+        private sealed class NonGenericToGenericIterator : IIterator<object?>
         {
             private IBindableIterator iterator;
 
             public NonGenericToGenericIterator(IBindableIterator iterator)
             { this.iterator = iterator; }
 
-            public object Current { get { return iterator.Current; } }
+            public object? Current { get { return iterator.Current; } }
             public bool HasCurrent { get { return iterator.HasCurrent; } }
             public bool MoveNext() { return iterator.MoveNext(); }
-            public int GetMany(object[] items) { throw new NotSupportedException(); }
+            public int GetMany(object?[] items) { throw new NotSupportedException(); }
         }
 
         // This method is invoked when GetEnumerator is called on a WinRT-backed implementation of IEnumerable.
         internal IEnumerator GetEnumerator_Stub()
         {
             IBindableIterable _this = Unsafe.As<IBindableIterable>(this);
-            return new IteratorToEnumeratorAdapter<object>(new NonGenericToGenericIterator(_this.First()));
+            return new IteratorToEnumeratorAdapter<object?>(new NonGenericToGenericIterator(_this.First()));
         }
     }
 
@@ -104,7 +99,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
     {
         private IIterator<T> m_iterator;
         private bool m_hadCurrent;
-        private T m_current;
+        private T m_current = default!; // TODO-NULLABLE-GENERIC
         private bool m_isInitialized;
 
         internal IteratorToEnumeratorAdapter(IIterator<T> iterator)
@@ -129,7 +124,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             }
         }
 
-        object IEnumerator.Current
+        object? IEnumerator.Current
         {
             get
             {
index 08eb22b..828fc15 100644 (file)
@@ -2,17 +2,9 @@
 // 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;
-using System.Security;
-using System.Reflection;
+#nullable enable
 using System.Collections;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
 using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
index 98beaf2..048435a 100644 (file)
@@ -2,16 +2,8 @@
 // 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;
-using System.Security;
-using System.Reflection;
+#nullable enable
 using System.Collections;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
@@ -47,12 +39,12 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         public IBindableIterator First()
         {
             IEnumerator enumerator = list.GetEnumerator();
-            return new EnumeratorToIteratorAdapter<object>(new EnumerableToBindableIterableAdapter.NonGenericToGenericEnumerator(enumerator));
+            return new EnumeratorToIteratorAdapter<object?>(new EnumerableToBindableIterableAdapter.NonGenericToGenericEnumerator(enumerator));
         }
 
         // IBindableVectorView implementation:
 
-        public object GetAt(uint index)
+        public object? GetAt(uint index)
         {
             EnsureIndexInt32(index, list.Count);
 
index 657eac0..9773d69 100644 (file)
@@ -2,17 +2,10 @@
 // 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;
-using System.Security;
-using System.Reflection;
-using System.Collections;
+#nullable enable
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
@@ -230,7 +223,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
             if (typeof(T) == typeof(string))
             {
-                string[] stringItems = items as string[];
+                string[] stringItems = (items as string[])!;
 
                 // Fill in rest of the array with string.Empty to avoid marshaling failure
                 for (uint i = itemCount; i < items.Length; ++i)
index 82ef71c..ab6fc31 100644 (file)
@@ -2,12 +2,8 @@
 // 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.Reflection;
-using System.Runtime.InteropServices;
-using System.Security;
 using System.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
@@ -50,7 +46,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         {
             try
             {
-                return Activator.CreateInstance(m_type);
+                return Activator.CreateInstance(m_type)!;
             }
             catch (MissingMethodException)
             {
@@ -59,7 +55,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             }
             catch (TargetInvocationException e)
             {
-                throw e.InnerException;
+                throw e.InnerException!;
             }
         }
 
index 487ebd1..c36fe91 100644 (file)
@@ -2,15 +2,9 @@
 // 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;
-using System.Security;
-using System.Collections;
+#nullable enable
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
index 8bd2020..10f2061 100644 (file)
@@ -2,15 +2,9 @@
 // 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;
-using System.Security;
-using System.Collections;
+#nullable enable
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
@@ -125,7 +119,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             IMap<K, V> _this = Unsafe.As<IMap<K, V>>(this);
             if (!_this.HasKey(key))
             {
-                value = default;
+                value = default!; // TODO-NULLABLE-GENERIC
                 return false;
             }
 
@@ -136,7 +130,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             }
             catch (KeyNotFoundException)
             {
-                value = default;
+                value = default!; // TODO-NULLABLE-GENERIC
                 return false;
             }
         }
index 290f927..eb70223 100644 (file)
@@ -2,15 +2,9 @@
 // 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;
-using System.Security;
-using System.Collections;
+#nullable enable
 using System.Collections.Generic;
 using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
index 201f4b1..f4abc61 100644 (file)
@@ -2,12 +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;
-using System.Runtime.InteropServices;
-using System.Security;
-
+#nullable enable
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
 #if BIT64
index f083eb2..5588faf 100644 (file)
@@ -2,14 +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;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Security;
-
+#nullable enable
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
     // Note this is a copy of the PropertyType enumeration from Windows.Foundation.winmd
index 2a6208f..0c555fe 100644 (file)
 ** 
 ===========================================================*/
 
-using System;
-using System.Runtime.InteropServices;
-using System.Runtime.InteropServices.WindowsRuntime;
+#nullable enable
 using System.Runtime.CompilerServices;
-using System.Security;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
@@ -30,7 +27,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
     internal class IStringableHelper
     {
-        internal static string ToString(object obj)
+        internal static string? ToString(object obj)
         {
             if (obj is IGetProxyTarget proxy)
                 obj = proxy.GetTarget();
@@ -97,9 +94,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         internal extern IntPtr GetRedirectedEqualsMD();
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        internal extern bool RedirectEquals(object obj, IntPtr pMD);
+        internal extern bool RedirectEquals(object? obj, IntPtr pMD);
 
-        public override bool Equals(object obj)
+        public override bool Equals(object? obj)
         {
             IntPtr pMD = GetRedirectedEqualsMD();
             if (pMD == IntPtr.Zero)
index bda5168..f7d44ff 100644 (file)
@@ -2,15 +2,8 @@
 // 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;
-using System.Security;
-using System.Collections;
-using System.Collections.Generic;
+#nullable enable
 using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
index 18c3596..704a45f 100644 (file)
@@ -2,15 +2,8 @@
 // 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;
-using System.Security;
-using System.Collections;
-using System.Collections.Generic;
+#nullable enable
 using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
index bc87efa..f76f331 100644 (file)
@@ -2,15 +2,8 @@
 // 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;
-using System.Security;
-using System.Collections;
-using System.Collections.Generic;
+#nullable enable
 using System.Diagnostics;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
 using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
index 1f6e373..fb5c116 100644 (file)
@@ -2,10 +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
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
     // WindowsFoundationEventHandler<T> a copy of the definition for the Windows.Foundation.EventHandler<T> delegate
index 5a151e7..3b0fd35 100644 (file)
@@ -2,16 +2,12 @@
 // 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.Reflection;
 using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
 using System.Threading;
-using System.Security;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
@@ -43,7 +39,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             // They have completely different implementation because native side has its own unique problem to solve -
             // there could be more than one RCW for the same COM object
             // it would be more confusing and less-performant if we were to merge them together
-            object target = removeMethod.Target;
+            object? target = removeMethod.Target;
             if (target == null || Marshal.IsComObject(target))
                 NativeOrStaticEventRegistrationImpl.AddEventHandler<T>(addMethod, removeMethod, handler);
             else
@@ -68,7 +64,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             // They have completely different implementation because native side has its own unique problem to solve -
             // there could be more than one RCW for the same COM object
             // it would be more confusing and less-performant if we were to merge them together
-            object target = removeMethod.Target;
+            object? target = removeMethod.Target;
             if (target == null || Marshal.IsComObject(target))
                 NativeOrStaticEventRegistrationImpl.RemoveEventHandler<T>(removeMethod, handler);
             else
@@ -84,7 +80,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             // They have completely different implementation because native side has its own unique problem to solve -
             // there could be more than one RCW for the same COM object
             // it would be more confusing and less-performant if we were to merge them together
-            object target = removeMethod.Target;
+            object? target = removeMethod.Target;
             if (target == null || Marshal.IsComObject(target))
                 NativeOrStaticEventRegistrationImpl.RemoveAllEventHandlers(removeMethod);
             else
@@ -124,7 +120,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         internal struct EventRegistrationTokenList
         {
             private EventRegistrationToken firstToken;     // Optimization for common case where there is only one token
-            private List<EventRegistrationToken> restTokens;     // Rest of the tokens
+            private List<EventRegistrationToken>? restTokens;     // Rest of the tokens
 
             internal EventRegistrationTokenList(EventRegistrationToken token)
             {
@@ -215,6 +211,8 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             {
                 Debug.Assert(addMethod != null);
                 Debug.Assert(removeMethod != null);
+                Debug.Assert(removeMethod.Target != null);
+                Debug.Assert(handler != null);
 
                 // Add the method, and make a note of the token -> delegate mapping.
                 object instance = removeMethod.Target;
@@ -250,14 +248,14 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
                 lock (s_eventRegistrations)
                 {
-                    Dictionary<MethodInfo, Dictionary<object, EventRegistrationTokenList>> instanceMap = null;
+                    Dictionary<MethodInfo, Dictionary<object, EventRegistrationTokenList>>? instanceMap = null;
                     if (!s_eventRegistrations.TryGetValue(instance, out instanceMap))
                     {
                         instanceMap = new Dictionary<MethodInfo, Dictionary<object, EventRegistrationTokenList>>();
                         s_eventRegistrations.Add(instance, instanceMap);
                     }
 
-                    Dictionary<object, EventRegistrationTokenList> tokens = null;
+                    Dictionary<object, EventRegistrationTokenList>? tokens = null;
                     if (!instanceMap.TryGetValue(removeMethod.Method, out tokens))
                     {
                         tokens = new Dictionary<object, EventRegistrationTokenList>();
@@ -271,6 +269,8 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             internal static void RemoveEventHandler<T>(Action<EventRegistrationToken> removeMethod, T handler)
             {
                 Debug.Assert(removeMethod != null);
+                Debug.Assert(removeMethod.Target != null);
+                Debug.Assert(handler != null);
 
                 object instance = removeMethod.Target;
                 Dictionary<object, EventRegistrationTokenList> registrationTokens = GetEventRegistrationTokenTable(instance, removeMethod);
@@ -312,6 +312,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             internal static void RemoveAllEventHandlers(Action<EventRegistrationToken> removeMethod)
             {
                 Debug.Assert(removeMethod != null);
+                Debug.Assert(removeMethod.Target != null);
 
                 object instance = removeMethod.Target;
                 Dictionary<object, EventRegistrationTokenList> registrationTokens = GetEventRegistrationTokenTable(instance, removeMethod);
@@ -522,7 +523,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             // Get InstanceKey to use in the cache
             private static object GetInstanceKey(Action<EventRegistrationToken> removeMethod)
             {
-                object target = removeMethod.Target;
+                object? target = removeMethod.Target;
                 Debug.Assert(target == null || Marshal.IsComObject(target), "Must be null or a RCW");
                 if (target == null)
                     return removeMethod.Method.DeclaringType;
@@ -531,7 +532,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                 return (object)Marshal.GetRawIUnknownForComObjectNoAddRef(target);
             }
 
-            private static object FindEquivalentKeyUnsafe(ConditionalWeakTable<object, EventRegistrationTokenListWithCount> registrationTable, object handler, out EventRegistrationTokenListWithCount tokens)
+            private static object? FindEquivalentKeyUnsafe(ConditionalWeakTable<object, EventRegistrationTokenListWithCount> registrationTable, object handler, out EventRegistrationTokenListWithCount? tokens) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
             {
                 foreach (KeyValuePair<object, EventRegistrationTokenListWithCount> item in registrationTable)
                 {
@@ -549,6 +550,8 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                                                   Action<EventRegistrationToken> removeMethod,
                                                   T handler)
             {
+                Debug.Assert(handler != null);
+
                 // The instanceKey will be IUnknown * of the target object
                 object instanceKey = GetInstanceKey(removeMethod);
 
@@ -562,7 +565,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
                 try
                 {
-                    EventRegistrationTokenListWithCount tokens;
+                    EventRegistrationTokenListWithCount? tokens;
 
                     //
                     // The whole add/remove code has to be protected by a reader/writer lock
@@ -572,7 +575,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                     try
                     {
                         // Add the method, and make a note of the delegate -> token mapping.
-                        TokenListCount tokenListCount;
+                        TokenListCount? tokenListCount;
                         ConditionalWeakTable<object, EventRegistrationTokenListWithCount> registrationTokens = GetOrCreateEventRegistrationTokenTable(instanceKey, removeMethod, out tokenListCount);
                         lock (registrationTokens)
                         {
@@ -589,7 +592,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                             // will be added into B's token list, but once we unsubscribe B, we might end up removing
                             // the last token in C, and that may lead to crash.
                             //
-                            object key = FindEquivalentKeyUnsafe(registrationTokens, handler, out tokens);
+                            object? key = FindEquivalentKeyUnsafe(registrationTokens, handler, out tokens);
                             if (key == null)
                             {
                                 tokens = new EventRegistrationTokenListWithCount(tokenListCount, token);
@@ -597,7 +600,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                             }
                             else
                             {
-                                tokens.Push(token);
+                                tokens!.Push(token); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
                             }
 
                             tokenAdded = true;
@@ -625,7 +628,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                 }
             }
 
-            private static ConditionalWeakTable<object, EventRegistrationTokenListWithCount> GetEventRegistrationTokenTableNoCreate(object instance, Action<EventRegistrationToken> removeMethod, out TokenListCount tokenListCount)
+            private static ConditionalWeakTable<object, EventRegistrationTokenListWithCount>? GetEventRegistrationTokenTableNoCreate(object instance, Action<EventRegistrationToken> removeMethod, out TokenListCount? tokenListCount)
             {
                 Debug.Assert(instance != null);
                 Debug.Assert(removeMethod != null);
@@ -638,11 +641,11 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                 Debug.Assert(instance != null);
                 Debug.Assert(removeMethod != null);
 
-                return GetEventRegistrationTokenTableInternal(instance, removeMethod, out tokenListCount, /* createIfNotFound = */ true);
+                return GetEventRegistrationTokenTableInternal(instance, removeMethod, out tokenListCount!, /* createIfNotFound = */ true)!;
             }
 
             // Get the event registration token table for an event.  These are indexed by the remove method of the event.
-            private static ConditionalWeakTable<object, EventRegistrationTokenListWithCount> GetEventRegistrationTokenTableInternal(object instance, Action<EventRegistrationToken> removeMethod, out TokenListCount tokenListCount, bool createIfNotFound)
+            private static ConditionalWeakTable<object, EventRegistrationTokenListWithCount>? GetEventRegistrationTokenTableInternal(object instance, Action<EventRegistrationToken> removeMethod, out TokenListCount? tokenListCount, bool createIfNotFound)
             {
                 Debug.Assert(instance != null);
                 Debug.Assert(removeMethod != null);
@@ -681,6 +684,8 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
             internal static void RemoveEventHandler<T>(Action<EventRegistrationToken> removeMethod, T handler)
             {
+                Debug.Assert(handler != null);
+
                 object instanceKey = GetInstanceKey(removeMethod);
 
                 EventRegistrationToken token;
@@ -692,8 +697,8 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                 s_eventCacheRWLock.AcquireReaderLock(Timeout.Infinite);
                 try
                 {
-                    TokenListCount tokenListCount;
-                    ConditionalWeakTable<object, EventRegistrationTokenListWithCount> registrationTokens = GetEventRegistrationTokenTableNoCreate(instanceKey, removeMethod, out tokenListCount);
+                    TokenListCount? tokenListCount;
+                    ConditionalWeakTable<object, EventRegistrationTokenListWithCount>? registrationTokens = GetEventRegistrationTokenTableNoCreate(instanceKey, removeMethod, out tokenListCount);
                     if (registrationTokens == null)
                     {
                         // We have no information regarding this particular instance (IUnknown*/type) - just return
@@ -704,7 +709,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
 
                     lock (registrationTokens)
                     {
-                        EventRegistrationTokenListWithCount tokens;
+                        EventRegistrationTokenListWithCount? tokens;
 
                         // Note:
                         // When unsubscribing events, we allow subscribing the event using a different delegate
@@ -713,7 +718,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                         // It actually doesn't matter which delegate - as long as it matches
                         // Note that inside TryGetValueWithValueEquality we assumes that any delegate
                         // with the same value equality would have the same hash code
-                        object key = FindEquivalentKeyUnsafe(registrationTokens, handler, out tokens);
+                        object? key = FindEquivalentKeyUnsafe(registrationTokens, handler, out tokens);
                         Debug.Assert((key != null && tokens != null) || (key == null && tokens == null),
                                         "key and tokens must be both null or non-null");
                         if (tokens == null)
@@ -738,7 +743,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                             // NOTE: We should not check whether registrationTokens has 0 entries and remove it from the cache
                             // (just like managed event implementation), because this might have raced with the finalizer of
                             // EventRegistrationTokenList
-                            registrationTokens.Remove(key);
+                            registrationTokens.Remove(key!); // TODO-NULLABLE: https://github.com/dotnet/csharplang/issues/2388
                         }
 
                         Log("[WinRT_Eventing] Event unsubscribed for managed instance = " + instanceKey + ", handler = " + handler + ", token = " + token.Value + "\n");
@@ -768,8 +773,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                 s_eventCacheRWLock.AcquireReaderLock(Timeout.Infinite);
                 try
                 {
-                    TokenListCount tokenListCount;
-                    ConditionalWeakTable<object, EventRegistrationTokenListWithCount> registrationTokens = GetEventRegistrationTokenTableNoCreate(instanceKey, removeMethod, out tokenListCount);
+                    ConditionalWeakTable<object, EventRegistrationTokenListWithCount>? registrationTokens = GetEventRegistrationTokenTableNoCreate(instanceKey, removeMethod, out _);
                     if (registrationTokens == null)
                     {
                         // We have no information regarding this particular instance (IUnknown*/type) - just return
@@ -838,8 +842,8 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                 private uint numReadWaiters;         // maximum number of threads that can be doing a WaitOne on the readEvent
 
                 // conditions we wait on.
-                private EventWaitHandle writeEvent;    // threads waiting to acquire a write lock go here.
-                private EventWaitHandle readEvent;     // threads waiting to acquire a read lock go here (will be released in bulk)
+                private EventWaitHandle? writeEvent;    // threads waiting to acquire a write lock go here.
+                private EventWaitHandle? readEvent;     // threads waiting to acquire a read lock go here (will be released in bulk)
 
                 internal MyReaderWriterLock()
                 {
@@ -918,7 +922,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                 /// while holding a spin lock).  If all goes well, reenter the lock and
                 /// set 'waitEvent'
                 /// </summary>
-                private void LazyCreateEvent(ref EventWaitHandle waitEvent, bool makeAutoResetEvent)
+                private void LazyCreateEvent(ref EventWaitHandle? waitEvent, bool makeAutoResetEvent)
                 {
                     Debug.Assert(myLock != 0, "Lock must be held");
                     Debug.Assert(waitEvent == null, "Wait event must be null");
@@ -973,15 +977,17 @@ namespace System.Runtime.InteropServices.WindowsRuntime
                     if (owners == 0 && numWriteWaiters > 0)
                     {
                         ExitMyLock();      // Exit before signaling to improve efficiency (wakee will need the lock)
-                        writeEvent.Set();   // release one writer.
+                        writeEvent!.Set(); // release one writer.  Must be non-null if there were waiters.
                     }
                     else if (owners >= 0 && numReadWaiters != 0)
                     {
                         ExitMyLock();    // Exit before signaling to improve efficiency (wakee will need the lock)
-                        readEvent.Set();  // release all readers.
+                        readEvent!.Set();  // release all readers.  Must be non-null if there were waiters.
                     }
                     else
+                    {
                         ExitMyLock();
+                    }
                 }
 
                 private void EnterMyLock()
@@ -1054,12 +1060,12 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             }
         }
 
-        internal static Exception GetExceptionForHR(int hresult, Exception innerException, string messageResource)
+        internal static Exception GetExceptionForHR(int hresult, Exception? innerException, string? messageResource)
         {
-            Exception e = null;
+            Exception? e = null;
             if (innerException != null)
             {
-                string message = innerException.Message;
+                string? message = innerException.Message;
                 if (message == null && messageResource != null)
                 {
                     message = SR.GetResourceString(messageResource);
@@ -1068,7 +1074,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             }
             else
             {
-                string message = (messageResource != null ? SR.GetResourceString(messageResource): null);
+                string? message = (messageResource != null ? SR.GetResourceString(messageResource): null);
                 e = new Exception(message);
             }
 
@@ -1076,7 +1082,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
             return e;
         }
 
-        internal static Exception GetExceptionForHR(int hresult, Exception innerException)
+        internal static Exception GetExceptionForHR(int hresult, Exception? innerException)
         {
             return GetExceptionForHR(hresult, innerException, null);
         }
@@ -1122,7 +1128,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime
         /// for the application to be invoked to process the error.
         /// </summary>
         /// <returns>true if the error was reported, false if not (ie running on Win8)</returns>
-        internal static bool ReportUnhandledError(Exception e)
+        internal static bool ReportUnhandledError(Exception? e)
         {
             // Only report to the WinRT global exception handler in modern apps
             if (!ApplicationModel.IsUap)
index b36266f..fe1dc91 100644 (file)
@@ -2,16 +2,8 @@
 // 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;
-using System.Collections.Generic;
+#nullable enable
 using System.Collections.ObjectModel;
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using System.Security;
 
 namespace System.Runtime.InteropServices.WindowsRuntime
 {
@@ -19,9 +11,9 @@ namespace System.Runtime.InteropServices.WindowsRuntime
     {
         private static EventHandler<DesignerNamespaceResolveEventArgs> DesignerNamespaceResolve;
 
-        internal static string[] OnDesignerNamespaceResolve(string namespaceName)
+        internal static string[]? OnDesignerNamespaceResolve(string namespaceName)
         {
-            EventHandler<DesignerNamespaceResolveEventArgs> eventHandler = DesignerNamespaceResolve;
+            EventHandler<DesignerNamespaceResolveEventArgs>? eventHandler = DesignerNamespaceResolve;
             if (eventHandler != null)
             {
                 foreach (EventHandler<DesignerNamespaceResolveEventArgs> handler in eventHandler.GetInvocationList())