Nullable: src\System\Runtime\InteropServices (#23936)
authorStephen Toub <stoub@microsoft.com>
Sat, 13 Apr 2019 04:42:33 +0000 (00:42 -0400)
committerGitHub <noreply@github.com>
Sat, 13 Apr 2019 04:42:33 +0000 (00:42 -0400)
* Nullable: src\System\Runtime\InteropServices

* Address PR feedback

14 files changed:
src/System.Private.CoreLib/shared/System/Delegate.cs
src/System.Private.CoreLib/shared/System/Gen2GcCallback.cs
src/System.Private.CoreLib/shared/System/Runtime/InteropServices/GCHandle.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/Attributes.cs [deleted file]
src/System.Private.CoreLib/src/System/Runtime/InteropServices/ComEventsHelper.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/ComEventsInfo.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/ComEventsMethod.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/ComEventsSink.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/CriticalHandle.CoreCLR.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.CoreCLR.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/IDispatch.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/NativeLibrary.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/Variant.cs
src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.CoreCLR.cs

index 0c60ba5..79c12c1 100644 (file)
@@ -13,7 +13,7 @@ namespace System
     {
         public virtual object Clone() => MemberwiseClone();
 
-        public static Delegate? Combine(Delegate? a, Delegate? b)
+        public static Delegate? Combine(Delegate? a, Delegate? b) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
         {
             if (a is null)
                 return b;
@@ -21,7 +21,7 @@ namespace System
             return a.CombineImpl(b);
         }
 
-        public static Delegate? Combine(params Delegate?[]? delegates)
+        public static Delegate? Combine(params Delegate?[]? delegates) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
         {
             if (delegates == null || delegates.Length == 0)
                 return null;
index 66cdcc7..72d11a9 100644 (file)
@@ -39,7 +39,7 @@ namespace System
         ~Gen2GcCallback()
         {
             // Check to see if the target object is still alive.
-            object targetObj = _weakTargetObj.Target;
+            object? targetObj = _weakTargetObj.Target;
             if (targetObj == null)
             {
                 // The target object is dead, so this callback object is no longer needed.
index 67e8ad2..4418b37 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
 using System.Diagnostics;
 using System.Runtime.CompilerServices;
 using System.Threading;
@@ -34,7 +35,7 @@ namespace System.Runtime.InteropServices
         private IntPtr _handle;
 
         // Allocate a handle storing the object and the type.
-        private GCHandle(object value, GCHandleType type)
+        private GCHandle(object? value, GCHandleType type)
         {
             // Make sure the type parameter is within the valid range for the enum.
             if ((uint)type > (uint)GCHandleType.Pinned) // IMPORTANT: This must be kept in sync with the GCHandleType enum.
@@ -64,13 +65,13 @@ namespace System.Runtime.InteropServices
         /// <summary>Creates a new GC handle for an object.</summary>
         /// <param name="value">The object that the GC handle is created for.</param>
         /// <returns>A new GC handle that protects the object.</returns>
-        public static GCHandle Alloc(object value) => new GCHandle(value, GCHandleType.Normal);
+        public static GCHandle Alloc(object? value) => new GCHandle(value, GCHandleType.Normal);
 
         /// <summary>Creates a new GC handle for an object.</summary>
         /// <param name="value">The object that the GC handle is created for.</param>
         /// <param name="type">The type of GC handle to create.</param>
         /// <returns>A new GC handle that protects the object.</returns>
-        public static GCHandle Alloc(object value, GCHandleType type) => new GCHandle(value, type);
+        public static GCHandle Alloc(object? value, GCHandleType type) => new GCHandle(value, type);
 
         /// <summary>Frees a GC handle.</summary>
         public void Free()
@@ -82,7 +83,7 @@ namespace System.Runtime.InteropServices
         }
 
         // Target property - allows getting / updating of the handle's referent.
-        public object Target
+        public object? Target
         {
             get
             {
@@ -168,7 +169,7 @@ namespace System.Runtime.InteropServices
 
         public override int GetHashCode() => _handle.GetHashCode();
 
-        public override bool Equals(object o) => o is GCHandle && _handle == ((GCHandle)o)._handle;
+        public override bool Equals(object? o) => o is GCHandle && _handle == ((GCHandle)o)._handle;
 
         public static bool operator ==(GCHandle a, GCHandle b) => a._handle == b._handle;
 
diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Attributes.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Attributes.cs
deleted file mode 100644 (file)
index ed7a28d..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace System.Runtime.InteropServices
-{
-    [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Enum | AttributeTargets.Struct | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
-    public sealed class TypeIdentifierAttribute : Attribute
-    {
-        public TypeIdentifierAttribute() { }
-        public TypeIdentifierAttribute(string scope, string identifier) { Scope_ = scope; Identifier_ = identifier; }
-
-        public string Scope { get { return Scope_; } }
-        public string Identifier { get { return Identifier_; } }
-
-        internal string Scope_;
-        internal string Identifier_;
-    }
-
-    // To be used on methods that sink reverse P/Invoke calls.
-    // This attribute is a CoreCLR-only security measure, currently ignored by the desktop CLR.
-    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
-    public sealed class AllowReversePInvokeCallsAttribute : Attribute
-    {
-        public AllowReversePInvokeCallsAttribute()
-        {
-        }
-    }
-
-    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Event, Inherited = false)]
-    public sealed class DispIdAttribute : Attribute
-    {
-        internal int _val;
-
-        public DispIdAttribute(int dispId)
-        {
-            _val = dispId;
-        }
-
-        public int Value => _val;
-    }
-
-    [AttributeUsage(AttributeTargets.Class, Inherited = false)]
-    public sealed class ComDefaultInterfaceAttribute : Attribute
-    {
-        internal Type _val;
-
-        public ComDefaultInterfaceAttribute(Type defaultInterface)
-        {
-            _val = defaultInterface;
-        }
-
-        public Type Value => _val;
-    }
-
-    public enum ClassInterfaceType
-    {
-        None = 0,
-        AutoDispatch = 1,
-        AutoDual = 2
-    }
-
-    [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class, Inherited = false)]
-    public sealed class ClassInterfaceAttribute : Attribute
-    {
-        internal ClassInterfaceType _val;
-
-        public ClassInterfaceAttribute(ClassInterfaceType classInterfaceType)
-        {
-            _val = classInterfaceType;
-        }
-
-        public ClassInterfaceAttribute(short classInterfaceType)
-        {
-            _val = (ClassInterfaceType)classInterfaceType;
-        }
-
-        public ClassInterfaceType Value => _val;
-    }
-
-    [AttributeUsage(AttributeTargets.Class, Inherited = false)]
-    public sealed class ProgIdAttribute : Attribute
-    {
-        internal string _val;
-
-        public ProgIdAttribute(string progId)
-        {
-            _val = progId;
-        }
-
-        public string Value => _val;
-    }
-
-    [AttributeUsage(AttributeTargets.Class, Inherited = true)]
-    public sealed class ComSourceInterfacesAttribute : Attribute
-    {
-        internal string _val;
-
-        public ComSourceInterfacesAttribute(string sourceInterfaces)
-        {
-            _val = sourceInterfaces;
-        }
-
-        public ComSourceInterfacesAttribute(Type sourceInterface)
-        {
-            _val = sourceInterface.FullName;
-        }
-    
-        public ComSourceInterfacesAttribute(Type sourceInterface1, Type sourceInterface2)
-        {
-            _val = sourceInterface1.FullName + "\0" + sourceInterface2.FullName;
-        }
-
-        public ComSourceInterfacesAttribute(Type sourceInterface1, Type sourceInterface2, Type sourceInterface3)
-        {
-            _val = sourceInterface1.FullName + "\0" + sourceInterface2.FullName + "\0" + sourceInterface3.FullName;
-        }
-
-        public ComSourceInterfacesAttribute(Type sourceInterface1, Type sourceInterface2, Type sourceInterface3, Type sourceInterface4)
-        {
-            _val = sourceInterface1.FullName + "\0" + sourceInterface2.FullName + "\0" + sourceInterface3.FullName + "\0" + sourceInterface4.FullName;
-        }
-
-        public string Value => _val;
-    }
-
-    [AttributeUsage(AttributeTargets.Interface, Inherited = false)]
-    public sealed class CoClassAttribute : Attribute
-    {
-        internal Type _CoClass;
-
-        public CoClassAttribute(Type coClass)
-        {
-            _CoClass = coClass;
-        }
-
-        public Type CoClass => _CoClass;
-    }
-}
index a5d431d..a462e93 100644 (file)
@@ -82,8 +82,7 @@
 // means that the problem is already quite complex and we should not be dealing with it - see
 // ComEventsMethod.Invoke
 
-using System;
-
+#nullable enable
 namespace System.Runtime.InteropServices
 {
     /// <summary>
@@ -105,13 +104,13 @@ namespace System.Runtime.InteropServices
             {
                 ComEventsInfo eventsInfo = ComEventsInfo.FromObject(rcw);
 
-                ComEventsSink sink = eventsInfo.FindSink(ref iid);
+                ComEventsSink? sink = eventsInfo.FindSink(ref iid);
                 if (sink == null)
                 {
                     sink = eventsInfo.AddSink(ref iid);
                 }
 
-                ComEventsMethod method = sink.FindMethod(dispid);
+                ComEventsMethod? method = sink.FindMethod(dispid);
                 if (method == null)
                 {
                     method = sink.AddMethod(dispid);
@@ -128,23 +127,23 @@ namespace System.Runtime.InteropServices
         /// <param name="iid">identifier of the source interface used by COM object to fire events</param>
         /// <param name="dispid">dispatch identifier of the method on the source interface</param>
         /// <param name="d">delegate to remove from the invocation list</param>
-        public static Delegate Remove(object rcw, Guid iid, int dispid, Delegate d)
+        public static Delegate? Remove(object rcw, Guid iid, int dispid, Delegate d)
         {
             lock (rcw)
             {
-                ComEventsInfo eventsInfo = ComEventsInfo.Find(rcw);
+                ComEventsInfo? eventsInfo = ComEventsInfo.Find(rcw);
                 if (eventsInfo == null)
                 {
                     return null;
                 }
 
-                ComEventsSink sink = eventsInfo.FindSink(ref iid);
+                ComEventsSink? sink = eventsInfo.FindSink(ref iid);
                 if (sink == null)
                 {
                     return null;
                 }
 
-                ComEventsMethod method = sink.FindMethod(dispid);
+                ComEventsMethod? method = sink.FindMethod(dispid);
                 if (method == null)
                 {
                     return null;
index 8b47683..623d241 100644 (file)
@@ -2,14 +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;
-using ComTypes = System.Runtime.InteropServices.ComTypes;
-
+#nullable enable
 namespace System.Runtime.InteropServices
 {
     internal class ComEventsInfo
     {
-        private ComEventsSink _sinks;
+        private ComEventsSink? _sinks;
         private object _rcw;
 
         private ComEventsInfo(object rcw)
@@ -23,15 +21,15 @@ namespace System.Runtime.InteropServices
             _sinks = ComEventsSink.RemoveAll(_sinks);
         }
 
-        public static ComEventsInfo Find(object rcw)
+        public static ComEventsInfo? Find(object rcw)
         {
-            return (ComEventsInfo)Marshal.GetComObjectData(rcw, typeof(ComEventsInfo));
+            return (ComEventsInfo?)Marshal.GetComObjectData(rcw, typeof(ComEventsInfo));
         }
 
         // it is caller's responsibility to call this method under lock(rcw)
         public static ComEventsInfo FromObject(object rcw)
         {
-            ComEventsInfo eventsInfo = Find(rcw);
+            ComEventsInfo? eventsInfo = Find(rcw);
             if (eventsInfo == null)
             {
                 eventsInfo = new ComEventsInfo(rcw);
@@ -40,7 +38,7 @@ namespace System.Runtime.InteropServices
             return eventsInfo;
         }
 
-        public ComEventsSink FindSink(ref Guid iid)
+        public ComEventsSink? FindSink(ref Guid iid)
         {
             return ComEventsSink.Find(_sinks, ref iid);
         }
@@ -57,8 +55,8 @@ namespace System.Runtime.InteropServices
         // it is caller's responsibility to call this method under lock(rcw)
         internal ComEventsSink RemoveSink(ComEventsSink sink)
         {
-            _sinks = ComEventsSink.Remove(_sinks, sink);
-            return _sinks;
+            _sinks = ComEventsSink.Remove(_sinks!, sink);
+            return _sinks!;
         }
     }
 }
index ce36100..fcaadd7 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.Generic;
 using System.Diagnostics;
-using System.Text;
-using System.Runtime.InteropServices;
 using System.Reflection;
 
 namespace System.Runtime.InteropServices
@@ -30,7 +28,7 @@ namespace System.Runtime.InteropServices
         {
             private bool _once = false;
             private int _expectedParamsCount;
-            private Type[] _cachedTargetTypes;
+            private Type?[]? _cachedTargetTypes;
 
             public DelegateWrapper(Delegate d)
             {
@@ -39,7 +37,7 @@ namespace System.Runtime.InteropServices
 
             public Delegate Delegate { get; set; }
 
-            public object Invoke(object[] args)
+            public object? Invoke(object[] args)
             {
                 if (Delegate == null)
                 {
@@ -58,7 +56,7 @@ namespace System.Runtime.InteropServices
                     {
                         if (_cachedTargetTypes[i] != null)
                         {
-                            args[i] = Enum.ToObject(_cachedTargetTypes[i], args[i]);
+                            args[i] = Enum.ToObject(_cachedTargetTypes[i]!, args[i]); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34644
                         }
                     }
                 }
@@ -73,10 +71,10 @@ namespace System.Runtime.InteropServices
 
                 bool needToHandleCoercion = false;
 
-                var targetTypes = new List<Type>();
+                var targetTypes = new List<Type?>();
                 foreach (ParameterInfo pi in parameters)
                 {
-                    Type targetType = null;
+                    Type? targetType = null;
 
                     // recognize only 'ref Enum' signatures and cache
                     // both enum type and the underlying type.
@@ -106,14 +104,14 @@ namespace System.Runtime.InteropServices
         private List<DelegateWrapper> _delegateWrappers = new List<DelegateWrapper>();
 
         private readonly int _dispid;
-        private ComEventsMethod _next;
+        private ComEventsMethod? _next;
 
         public ComEventsMethod(int dispid)
         {
             _dispid = dispid;
         }
 
-        public static ComEventsMethod Find(ComEventsMethod methods, int dispid)
+        public static ComEventsMethod? Find(ComEventsMethod? methods, int dispid)
         {
             while (methods != null && methods._dispid != dispid)
             {
@@ -123,24 +121,25 @@ namespace System.Runtime.InteropServices
             return methods;
         }
 
-        public static ComEventsMethod Add(ComEventsMethod methods, ComEventsMethod method)
+        public static ComEventsMethod Add(ComEventsMethod? methods, ComEventsMethod method)
         {
             method._next = methods;
             return method;
         }
 
-        public static ComEventsMethod Remove(ComEventsMethod methods, ComEventsMethod method)
+        public static ComEventsMethod? Remove(ComEventsMethod methods, ComEventsMethod method)
         {
             Debug.Assert(methods != null, "removing method from empty methods collection");
             Debug.Assert(method != null, "specify method is null");
 
             if (methods == method)
             {
-                methods = methods._next;
+                return methods._next;
             }
             else
             {
-                ComEventsMethod current = methods;
+                ComEventsMethod? current = methods;
+
                 while (current != null && current._next != method)
                 {
                     current = current._next;
@@ -150,9 +149,9 @@ namespace System.Runtime.InteropServices
                 {
                     current._next = method._next;
                 }
-            }
 
-            return methods;
+                return methods;
+            }
         }
 
         public bool Empty
@@ -175,7 +174,7 @@ namespace System.Runtime.InteropServices
                 {
                     if (wrapper.Delegate.GetType() == d.GetType())
                     {
-                        wrapper.Delegate = Delegate.Combine(wrapper.Delegate, d);
+                        wrapper.Delegate = Delegate.Combine(wrapper.Delegate, d)!; // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
                         return;
                     }
                 }
@@ -191,7 +190,7 @@ namespace System.Runtime.InteropServices
             {
                 // Find delegate wrapper index
                 int removeIdx = -1;
-                DelegateWrapper wrapper = null;
+                DelegateWrapper? wrapper = null;
                 for (int i = 0; i < _delegateWrappers.Count; i++)
                 {
                     DelegateWrapper wrapperMaybe = _delegateWrappers[i];
@@ -210,7 +209,7 @@ namespace System.Runtime.InteropServices
                 }
 
                 // Update wrapper or remove from collection
-                Delegate newDelegate = Delegate.Remove(wrapper.Delegate, d);
+                Delegate? newDelegate = Delegate.Remove(wrapper!.Delegate, d);
                 if (newDelegate != null)
                 {
                     wrapper.Delegate = newDelegate;
@@ -222,10 +221,10 @@ namespace System.Runtime.InteropServices
             }
         }
 
-        public object Invoke(object[] args)
+        public object? Invoke(object[] args)
         {
             Debug.Assert(!Empty);
-            object result = null;
+            object? result = null;
 
             lock (_delegateWrappers)
             {
index c5262a6..0a8780b 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.Diagnostics;
 
-using Variant = System.Runtime.InteropServices.Variant;
-
 namespace System.Runtime.InteropServices
 {
     /// <summary>
@@ -16,10 +14,10 @@ namespace System.Runtime.InteropServices
     internal class ComEventsSink : IDispatch, ICustomQueryInterface
     {
         private Guid _iidSourceItf;
-        private ComTypes.IConnectionPoint _connectionPoint;
+        private ComTypes.IConnectionPoint? _connectionPoint;
         private int _cookie;
-        private ComEventsMethod _methods;
-        private ComEventsSink _next;
+        private ComEventsMethod? _methods;
+        private ComEventsSink? _next;
 
         public ComEventsSink(object rcw, Guid iid)
         {
@@ -27,9 +25,9 @@ namespace System.Runtime.InteropServices
             this.Advise(rcw);
         }
 
-        public static ComEventsSink Find(ComEventsSink sinks, ref Guid iid)
+        public static ComEventsSink? Find(ComEventsSink? sinks, ref Guid iid)
         {
-            ComEventsSink sink = sinks;
+            ComEventsSink? sink = sinks;
             while (sink != null && sink._iidSourceItf != iid)
             {
                 sink = sink._next;
@@ -38,13 +36,13 @@ namespace System.Runtime.InteropServices
             return sink;
         }
 
-        public static ComEventsSink Add(ComEventsSink sinks, ComEventsSink sink)
+        public static ComEventsSink Add(ComEventsSink? sinks, ComEventsSink sink)
         {
             sink._next = sinks;
             return sink;
         }
 
-        public static ComEventsSink RemoveAll(ComEventsSink sinks)
+        public static ComEventsSink? RemoveAll(ComEventsSink? sinks)
         {
             while (sinks != null)
             {
@@ -55,18 +53,20 @@ namespace System.Runtime.InteropServices
             return null;
         }
 
-        public static ComEventsSink Remove(ComEventsSink sinks, ComEventsSink sink)
+        public static ComEventsSink? Remove(ComEventsSink sinks, ComEventsSink sink)
         {
             Debug.Assert(sinks != null, "removing event sink from empty sinks collection");
             Debug.Assert(sink != null, "specify event sink is null");
 
+            ComEventsSink? toReturn = sinks;
+
             if (sink == sinks)
             {
-                sinks = sinks._next;
+                toReturn = sinks._next;
             }
             else
             {
-                ComEventsSink current = sinks;
+                ComEventsSink? current = sinks;
                 while (current != null && current._next != sink)
                 {
                     current = current._next;
@@ -80,16 +80,16 @@ namespace System.Runtime.InteropServices
 
             sink.Unadvise();
 
-            return sinks;
+            return toReturn;
         }
 
-        public ComEventsMethod RemoveMethod(ComEventsMethod method)
+        public ComEventsMethod? RemoveMethod(ComEventsMethod method)
         {
-            _methods = ComEventsMethod.Remove(_methods, method);
+            _methods = ComEventsMethod.Remove(_methods!, method);
             return _methods;
         }
 
-        public ComEventsMethod FindMethod(int dispid)
+        public ComEventsMethod? FindMethod(int dispid)
         {
             return ComEventsMethod.Find(_methods, dispid);
         }
@@ -148,7 +148,7 @@ namespace System.Runtime.InteropServices
             IntPtr pExcepInfo,
             IntPtr puArgErr)
         {
-            ComEventsMethod method = FindMethod(dispid);
+            ComEventsMethod? method = FindMethod(dispid);
             if (method == null)
             {
                 return;
@@ -158,7 +158,7 @@ namespace System.Runtime.InteropServices
             // arguments marshalling. see code:ComEventsHelper#ComEventsArgsMarshalling
 
             const int InvalidIdx = -1;
-            object [] args = new object[pDispParams.cArgs];
+            object[] args = new object[pDispParams.cArgs];
             int [] byrefsMap = new int[pDispParams.cArgs];
             bool [] usedArgs = new bool[pDispParams.cArgs];
 
@@ -173,7 +173,7 @@ namespace System.Runtime.InteropServices
             {
                 pos = namedArgs[i];
                 ref Variant pvar = ref GetVariant(ref vars[i]);
-                args[pos] = pvar.ToObject();
+                args[pos] = pvar.ToObject()!;
                 usedArgs[pos] = true;
 
                 int byrefIdx = InvalidIdx;
@@ -196,7 +196,7 @@ namespace System.Runtime.InteropServices
                 }
 
                 ref Variant pvar = ref GetVariant(ref vars[pDispParams.cArgs - 1 - i]);
-                args[pos] = pvar.ToObject();
+                args[pos] = pvar.ToObject()!;
 
                 int byrefIdx = InvalidIdx;
                 if (pvar.IsByRef)
@@ -210,7 +210,7 @@ namespace System.Runtime.InteropServices
             }
 
             // Do the actual delegate invocation
-            object result = method.Invoke(args);
+            object? result = method.Invoke(args);
 
             // convert result to VARIANT
             if (pVarResult != IntPtr.Zero)
@@ -250,7 +250,7 @@ namespace System.Runtime.InteropServices
 
             ComTypes.IConnectionPointContainer cpc = (ComTypes.IConnectionPointContainer)rcw;
             ComTypes.IConnectionPoint cp;
-            cpc.FindConnectionPoint(ref _iidSourceItf, out cp);
+            cpc.FindConnectionPoint(ref _iidSourceItf, out cp!);
 
             object sinkObject = this;
 
index 803504a..d2a65f4 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
 using System.Runtime.CompilerServices;
 using System.Runtime.ConstrainedExecution;
 
index 6e09a0c..3576534 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
 using System.Runtime.CompilerServices;
 #if BIT64
 using nint = System.Int64;
@@ -15,7 +16,7 @@ namespace System.Runtime.InteropServices
     public partial struct GCHandle
     {
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern IntPtr InternalAlloc(object value, GCHandleType type);
+        private static extern IntPtr InternalAlloc(object? value, GCHandleType type);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         internal static extern void InternalFree(IntPtr handle);
@@ -30,9 +31,9 @@ namespace System.Runtime.InteropServices
 #endif
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        private static extern void InternalSet(IntPtr handle, object value);
+        private static extern void InternalSet(IntPtr handle, object? value);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
-        internal static extern object InternalCompareExchange(IntPtr handle, object value, object oldValue);
+        internal static extern object? InternalCompareExchange(IntPtr handle, object? value, object? oldValue);
     }
 }
index fbe70fe..1284878 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
 using System;
 using System.Collections.Generic;
 using System.Text;
index ca70d5d..fd0318e 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
 using System.Reflection;
 using System.Runtime.CompilerServices;
 using System.Threading;
@@ -179,7 +180,7 @@ namespace System.Runtime.InteropServices
         /// Therefore, this table uses weak assembly pointers to indirectly achieve 
         /// similar behavior.
         /// </summary>
-        private static ConditionalWeakTable<Assembly, DllImportResolver> s_nativeDllResolveMap = null;
+        private static ConditionalWeakTable<Assembly, DllImportResolver>? s_nativeDllResolveMap;
 
         /// <summary>
         /// Set a callback for resolving native library imports from an assembly.
@@ -210,7 +211,7 @@ namespace System.Runtime.InteropServices
 
             try
             {
-                s_nativeDllResolveMap.Add(assembly, resolver);
+                s_nativeDllResolveMap!.Add(assembly, resolver); // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/26761
             }
             catch (ArgumentException)
             {
index c726255..f9c1725 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
 using System.Diagnostics;
 
 namespace System.Runtime.InteropServices
@@ -227,7 +228,7 @@ namespace System.Runtime.InteropServices
         /// Get the managed object representing the Variant.
         /// </summary>
         /// <returns></returns>
-        public object ToObject()
+        public object? ToObject()
         {
             // Check the simple case upfront
             if (IsEmpty)
@@ -644,7 +645,7 @@ namespace System.Runtime.InteropServices
 
         // VT_UNKNOWN
 
-        public object AsUnknown
+        public object? AsUnknown
         {
             get
             {
@@ -672,7 +673,7 @@ namespace System.Runtime.InteropServices
 
         // VT_DISPATCH
 
-        public object AsDispatch
+        public object? AsDispatch
         {
             get
             {
index 73511d3..c9bb722 100644 (file)
@@ -86,7 +86,7 @@ namespace System.Runtime.Loader
         // implementation.
         private static Assembly? Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
         {
-            AssemblyLoadContext context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchManagedAssemblyLoadContext).Target);
+            AssemblyLoadContext context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchManagedAssemblyLoadContext).Target)!;
 
             return context.ResolveUsingLoad(assemblyName);
         }
@@ -95,7 +95,7 @@ namespace System.Runtime.Loader
         // after trying assembly resolution via Load override and TPA load context without success.
         private static Assembly ResolveUsingResolvingEvent(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
         {
-            AssemblyLoadContext context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchManagedAssemblyLoadContext).Target);
+            AssemblyLoadContext context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchManagedAssemblyLoadContext).Target)!;
 
             // Invoke the AssemblyResolve event callbacks if wired up
             return context.ResolveUsingEvent(assemblyName);
@@ -191,7 +191,7 @@ namespace System.Runtime.Loader
         // implementation.
         private static IntPtr ResolveUnmanagedDll(string unmanagedDllName, IntPtr gchManagedAssemblyLoadContext)
         {
-            AssemblyLoadContext context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchManagedAssemblyLoadContext).Target);
+            AssemblyLoadContext context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchManagedAssemblyLoadContext).Target)!;
             return context.LoadUnmanagedDll(unmanagedDllName);
         }
 
@@ -199,7 +199,7 @@ namespace System.Runtime.Loader
         // after trying all other means of resolution.
         private static IntPtr ResolveUnmanagedDllUsingEvent(string unmanagedDllName, Assembly assembly, IntPtr gchManagedAssemblyLoadContext)
         {
-            AssemblyLoadContext context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchManagedAssemblyLoadContext).Target);
+            AssemblyLoadContext context = (AssemblyLoadContext)(GCHandle.FromIntPtr(gchManagedAssemblyLoadContext).Target)!;
             return context.GetResolvedUnmanagedDll(assembly, unmanagedDllName);
         }
 
@@ -273,7 +273,7 @@ namespace System.Runtime.Loader
                 }
                 else
                 {
-                    loadContextForAssembly = (AssemblyLoadContext)(GCHandle.FromIntPtr(ptrAssemblyLoadContext).Target);
+                    loadContextForAssembly = (AssemblyLoadContext)(GCHandle.FromIntPtr(ptrAssemblyLoadContext).Target)!;
                 }
             }