Nullable: System.Runtime.InteropServices.dll
authorStephen Toub <stoub@microsoft.com>
Wed, 17 Apr 2019 21:47:39 +0000 (17:47 -0400)
committerStephen Toub <stoub@microsoft.com>
Thu, 9 May 2019 10:42:58 +0000 (06:42 -0400)
Commit migrated from https://github.com/dotnet/corefx/commit/b7617868a15031f2c5f5635864f32f68b3ddfa4b

src/libraries/System.Runtime.InteropServices/src/System.Runtime.InteropServices.csproj
src/libraries/System.Runtime.InteropServices/src/System/Runtime/CompilerServices/IDispatchConstantAttribute.cs
src/libraries/System.Runtime.InteropServices/src/System/Runtime/CompilerServices/IUnknownConstantAttribute.cs
src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComAwareEventInfo.cs
src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/IDataObject.cs
src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/ComTypes/STGMEDIUM.cs
src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/HandleCollector.cs
src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/RuntimeEnvironment.cs

index 1c3011b..0e208b6 100644 (file)
@@ -7,6 +7,7 @@
     <GenFacadesIgnoreMissingTypes Condition="'$(TargetsAOT)' == 'true'">true</GenFacadesIgnoreMissingTypes>
     <NoWarn Condition="'$(TargetsAOT)' == 'true'">$(NoWarn);0436;3001</NoWarn>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <NullableContextOptions>enable</NullableContextOptions>
     <Configurations>netcoreapp-Unix-Debug;netcoreapp-Unix-Release;netcoreapp-Windows_NT-Debug;netcoreapp-Windows_NT-Release;uap-Windows_NT-Debug;uap-Windows_NT-Release;uapaot-Windows_NT-Debug;uapaot-Windows_NT-Release</Configurations>
   </PropertyGroup>
   <ItemGroup>
index 89338b7..66e87d4 100644 (file)
@@ -11,6 +11,8 @@ namespace System.Runtime.CompilerServices
     {
         public IDispatchConstantAttribute() { }
 
+#pragma warning disable CS8608 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/23268
         public override object Value => new DispatchWrapper(null);
+#pragma warning restore CS8608
     }
 }
index 7b0f4b4..1001318 100644 (file)
@@ -11,6 +11,8 @@ namespace System.Runtime.CompilerServices
     {
         public IUnknownConstantAttribute() { }
 
+#pragma warning disable CS8608 // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/23268
         public override object Value => new UnknownWrapper(null);
+#pragma warning restore CS8608
     }
 }
index 016a1fe..39a5ab9 100644 (file)
@@ -4,7 +4,10 @@
 
 using System.Collections.Generic;
 using System.Reflection;
-using System.Security;
+
+// This type is obsolete, and is expected to be used in very specific ways or it may
+// throw null reference exceptions.
+#pragma warning disable CS8610
 
 namespace System.Runtime.InteropServices
 {
@@ -14,7 +17,7 @@ namespace System.Runtime.InteropServices
 
         public ComAwareEventInfo(Type type, string eventName)
         {
-            _innerEventInfo = type.GetEvent(eventName);
+            _innerEventInfo = type.GetEvent(eventName)!;
         }
 
         public override void AddEventHandler(object target, Delegate handler)
@@ -50,15 +53,15 @@ namespace System.Runtime.InteropServices
 
         public override EventAttributes Attributes => _innerEventInfo.Attributes;
 
-        public override MethodInfo GetAddMethod(bool nonPublic) => _innerEventInfo.GetAddMethod(nonPublic);
+        public override MethodInfo? GetAddMethod(bool nonPublic) => _innerEventInfo.GetAddMethod(nonPublic);
 
-        public override MethodInfo[] GetOtherMethods(bool nonPublic) => _innerEventInfo.GetOtherMethods(nonPublic);
+        public override MethodInfo[]? GetOtherMethods(bool nonPublic) => _innerEventInfo.GetOtherMethods(nonPublic);
 
-        public override MethodInfo GetRaiseMethod(bool nonPublic) => _innerEventInfo.GetRaiseMethod(nonPublic);
+        public override MethodInfo? GetRaiseMethod(bool nonPublic) => _innerEventInfo.GetRaiseMethod(nonPublic);
 
-        public override MethodInfo GetRemoveMethod(bool nonPublic) => _innerEventInfo.GetRemoveMethod(nonPublic);
+        public override MethodInfo? GetRemoveMethod(bool nonPublic) => _innerEventInfo.GetRemoveMethod(nonPublic);
 
-        public override Type DeclaringType => _innerEventInfo.DeclaringType;
+        public override Type? DeclaringType => _innerEventInfo.DeclaringType;
 
         public override object[] GetCustomAttributes(Type attributeType, bool inherit)
         {
@@ -83,11 +86,11 @@ namespace System.Runtime.InteropServices
 
         public override string Name => _innerEventInfo.Name;
 
-        public override Type ReflectedType => _innerEventInfo.ReflectedType;
+        public override Type? ReflectedType => _innerEventInfo.ReflectedType;
 
         private static void GetDataForComInvocation(EventInfo eventInfo, out Guid sourceIid, out int dispid)
         {
-            object[] comEventInterfaces = eventInfo.DeclaringType.GetCustomAttributes(typeof(ComEventInterfaceAttribute), inherit: false);
+            object[] comEventInterfaces = eventInfo.DeclaringType!.GetCustomAttributes(typeof(ComEventInterfaceAttribute), inherit: false);
 
             if (comEventInterfaces == null || comEventInterfaces.Length == 0)
             {
@@ -102,8 +105,8 @@ namespace System.Runtime.InteropServices
             Type sourceInterface = ((ComEventInterfaceAttribute)comEventInterfaces[0]).SourceInterface;
             Guid guid = sourceInterface.GUID;
 
-            MethodInfo methodInfo = sourceInterface.GetMethod(eventInfo.Name);
-            Attribute dispIdAttribute = Attribute.GetCustomAttribute(methodInfo, typeof(DispIdAttribute));
+            MethodInfo methodInfo = sourceInterface.GetMethod(eventInfo.Name)!;
+            Attribute? dispIdAttribute = Attribute.GetCustomAttribute(methodInfo, typeof(DispIdAttribute));
             if (dispIdAttribute == null)
             {
                 throw new InvalidOperationException(SR.InvalidOperation_NoDispIdAttribute);
index 57c8bc9..ece9f14 100644 (file)
@@ -83,6 +83,6 @@ namespace System.Runtime.InteropServices.ComTypes
         ///     Creates an object that can be used to enumerate the current advisory connections.
         /// </summary>
         [PreserveSig]
-        int EnumDAdvise(out IEnumSTATDATA enumAdvise);
+        int EnumDAdvise(out IEnumSTATDATA? enumAdvise);
     }
 }
index 7e63ccf..2e31b14 100644 (file)
@@ -9,6 +9,6 @@ namespace System.Runtime.InteropServices.ComTypes
         public TYMED tymed;
         public IntPtr unionmember;
         [MarshalAs(UnmanagedType.IUnknown)]
-        public object pUnkForRelease;
+        public object? pUnkForRelease;
     }
 }
index 879843c..61017cb 100644 (file)
@@ -16,12 +16,12 @@ namespace System.Runtime.InteropServices
         private int[] _gcCounts = new int[3];
         private int _gcGeneration = 0;
 
-        public HandleCollector(string name, int initialThreshold) :
+        public HandleCollector(string? name, int initialThreshold) :
             this(name, initialThreshold, int.MaxValue)
         {
         }
 
-        public HandleCollector(string name, int initialThreshold, int maximumThreshold)
+        public HandleCollector(string? name, int initialThreshold, int maximumThreshold)
         {
             if (initialThreshold < 0)
             {
index b68f90b..57a988d 100644 (file)
@@ -15,7 +15,7 @@ namespace System.Runtime.InteropServices
 
         public static string GetRuntimeDirectory()
         {
-            string runtimeDirectory = typeof(object).Assembly.Location;
+            string? runtimeDirectory = typeof(object).Assembly.Location;
             if (!Path.IsPathRooted(runtimeDirectory))
             {
                 runtimeDirectory = AppDomain.CurrentDomain.BaseDirectory;