Nullable: System.Runtime.InteropServices.CustomMarshalers/WindowsRuntime (dotnet...
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)
Commit migrated from https://github.com/dotnet/coreclr/commit/7e59345d1c394bcbf6e428e898d69cfb564b387e

51 files changed:
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/ComTypes/IEnumerable.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/EnumVariantViewOfEnumerator.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/EnumerableToDispatchMarshaler.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/EnumerableViewOfDispatch.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/EnumeratorToEnumVariantMarshaler.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/EnumeratorViewOfEnumVariant.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/ExpandoToDispatchExMarshaler.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/CustomMarshalers/TypeToTypeInfoMarshaler.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToCollectionAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/BindableVectorToListAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CLRIKeyValuePairImpl.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ConstantSplittableMap.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/CustomPropertyImpl.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryKeyCollection.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryToMapAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/DictionaryValueCollection.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/EnumeratorToIteratorAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationTokenTable.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IActivationFactory.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IClosable.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomProperty.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ICustomPropertyProvider.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IIterable.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IIterator.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IMap.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IMapViewToIReadOnlyDictionaryAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IPropertyValue.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyDictionaryToIMapViewAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IReadOnlyListToIVectorViewAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IReference.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IRestrictedErrorInfo.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IVector.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IVectorViewToIReadOnlyListAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/IteratorToEnumeratorAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ListToBindableVectorViewAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ListToVectorAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/ManagedActivationFactory.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/MapToCollectionAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/MapToDictionaryAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/MapViewToReadOnlyCollectionAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/NativeMethods.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/PropertyValue.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/RuntimeClass.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToCollectionAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/VectorToListAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/VectorViewToReadOnlyCollectionAdapter.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsFoundationEventHandler.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMarshal.cs
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/WindowsRuntimeMetadata.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ICustomMarshaler.cs

index e541960cae7137b52ab43bce6b484822bd50872e..68efabcd79a9c27b3bf9aaf268b2ed52b7347e24 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 d43b68252d5f858c8ce823e72974e3be3793a238..670aea6f09a77ce9d20b117f154bcc6e49ed5a5e 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 332a885507a2349178a9c56760d9764c1e2103f3..93058a34ef9f36a27d6111801f69079fd7404564 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 67bb393c676b732fcb8a17ca56e59309c6e2263e..298833256e63e50b3ca8fa0d2c8ad67ee7c9f520 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 fddc0c70ba75e61b5e5d5611488ba2206e1a5e8f..6e5e7b14960658fc89864049b0d03f6c59880791 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 b5ef969ac1bfd7fdecd72cce52cbe627ebc11e96..bb2839d258c682be896c85fb6bd8be42630b66d3 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 3cd8292e5bb5e7515387531193a986ddbd89d217..30b55cc81c294d1b01a4c45a6fd7291b072f2df7 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 eeae079d73aed6fec05488163d96d6edd990be38..eda7c8507158915527cc656a80e41047cc90712d 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 ce4be3415e7c3cf3fa7284f782245410c681de6c..201e23b6e4cc10ba14e8ba8d53d4c78aae4be539 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 6542f5cf26c445b676b125bb2d8021012350b8f4..5ac54b7d41cfbffad59e711feecbb73c2b1f7860 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 92c78f9ea2d5ca8e92ea76251d7e2196f801ab2c..2575794355e34e46989d58c0c0f24af7b6b6440d 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 a21d6a03b6badb2c450890c8f3915955fa9ff1ed..8a3ed8a97b85354432b1cbd5f914ce1a2e6b4e60 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 6874148191aa1805718a240fcbb4191eb04301f8..10d663b1baed3c7976b247708c4c5bc55dd30b46 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 2751209638b1b97f512b13e1d5df81b8b94f7f60..70e046d7ed04f9fc4eb51bc50b6cfbe8d450bae1 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 53a889e6517545a63610c15c3be3c42e15896f4e..b78fef6918bc9befe71876081488b7033393de4c 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 b1d9c8cb3a8b1fd88eb7b68cb7e7ef99da989472..eb851610e67ab212d4973559f9d343acd425e477 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 5299af3b93ec2d009f4d063ed05b06f0f3cb5526..bde80a9b665b8b19924768bd2a62b501c190ea96 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 0fb88950391eb454ba96f6ce90b61a864c0cae4d..a69a1a824c87e17562b7685c157f94273ed458fd 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 0ce01f86534ee17c490c5deb45b311944efd25d3..578d219e5374a053488e4fa1f7dd637ba42a877c 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 7891fd46665059737ea0776a10d0dcc09354d1ae..8b85d5c413b9927c51566366b0f52c89a407223f 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 07fb8f171a3bdf98b00e8fd5c0d338878ed41a09..30075ccfa31b0745e3411a2ab796c07fda0b2532 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 56cc2f6a4d93e6ce9279b03bdba2138ac65de014..78d399b7e3e6707839c63be4e6c1ce0dfee437f1 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 a44591245f3d240e75f405211e5752f8901f2703..94a00d31b56d2100a6f4519d45030e438bf9f5fe 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 00d622b711bf81913c3b26784ea0ea6ccefc6ffc..27ebdfb222cf75fe981e178c77446a80837dacfe 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 02dff54eac4ecd892f63183b26ea6319e1bf7abf..0f684be627370c182956bcb6ce997c02edcdb5d5 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 3a8086096b7c5f364e6e1f04b8bc3a0af25f9f68..d81cb6c4c95cf5e8b2833451f108fd5c9b2dba6a 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 aefa7be4d1dbe33aa062e9bfad7361bb73de65f9..5ad32eaf380e61680f5e3982b97ccbba415483e0 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 01e8f7b44c8e81e48f5900d6ec1a057a98c78e90..0e80f0a56daff17e2cd8004232c7f509593f49eb 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 6269f2e200109cc3762aa2c1b02457cfaf2d6e8c..d608a8aef827ff737198b4cb222e5903b97cd57f 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 d0101dafc9caafd3f9cad2285ce4a0eca7b3a318..844f866ede79f1776fbaf8509bdd9754e0d0dc0c 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 03faef0adbd39788ee7c54c07f64aa89473a66e3..db8dc3842ed1a90f21f40a3e35fd5c6b6eab5a6b 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 f00a7d35045016b22a5071fee5649d920ae08dfe..70872391135a3944765886806b2bdc23d4e8cdd7 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 f6667acf72ff9a159e6da152a144aa45e9182090..0bc7d04b180660df1b15f7ea52befd2798b46105 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 d49836c46a244a6a227c614d420125d68efa675c..ad8ec67e2c2911fb4729f6e910f0e0e129457ecb 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 08eb22b8e9de78f90113bcbb2beaab5fb8a236e0..828fc15e2988b02a2e7a962dd9e242ff908bc12a 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 98beaf22f238464aa87bc564eb7181fbcd286ecc..048435a0f04f0b015f9440331e267f53dd46886e 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 657eac0bfc8217e6a738f8d30dff2317281ab04a..9773d69ba6859ccc888aa15faee927614e50054c 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 82ef71c783fd8266f709429061746b2875683067..ab6fc315beebdbe121f32af1e17744b86c46943e 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 487ebd160abdc6cbdc0553b3d64ce5d53323060d..c36fe91d09fd7f4ecf68cf6c71531a8ebe51464f 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 8bd202042abad1b121d09d941d342f8873e59e71..10f2061d8a554cb92aa177992ecc048672810642 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 290f927d0d941260c163222d9a608a4a92687970..eb7022367a039523c5d9d05d7d20ae0aaf7b5a61 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 201f4b132b97dcff905f7f622b24127705dc4af6..f4abc61d044359b65a23cba9de166c3d90993ed1 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 f083eb29b86f90c8449e80b14da4344a5fa269e6..5588fafe06ddcff918d54248ba6c392fd476f1d9 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 2a6208f1bba13967b0f6edb486f16f8be2b10ac7..0c555fe0020f235c7dd65d7294765cc8c02f4675 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 bda5168814a4d76d1cc5c92687a1718662e29b66..f7d44ffeaaceeb254aa6cb17f46429c4eabb2090 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 18c3596d49a2f1754cd08b3cc00925398aa31a37..704a45fb279a38025675309be9f5ffe0b442b235 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 bc87efa6dcb22194a62a4fffe30429d22ff67bcc..f76f331699253584b2e78d4abd2d90345b020f3f 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 1f6e373842cb76739f47b9f2c11550f6cee08e9f..fb5c1163e16cfe093c82755c37a6b13dd85e02be 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 5a151e7de216ce7d7b68632a5ecf754db3d287c3..3b0fd3581d8ecb876fe419aea81c555d33bade55 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 b36266f769adbccd1cd485869ce7a1a088f5f26c..fe1dc917117ecc88027f87fbbab583680de88f00 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())
index cf442d4fde1f07a72644746b7ba44787232d3ac6..6a5f5d89d3bc442e0269ce70921c13ef864e3b24 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.