Simplify how CheckGCMode gets the Marshal type (#54000)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Thu, 10 Jun 2021 17:25:33 +0000 (19:25 +0200)
committerGitHub <noreply@github.com>
Thu, 10 Jun 2021 17:25:33 +0000 (10:25 -0700)
Unless I'm missing something, this is equivalent. The previous version was incomprehensible to static analysis.

src/tests/Interop/common/CheckGCMode.cs

index e895cd5..e3c6da3 100644 (file)
@@ -3,6 +3,7 @@
 
 using System;
 using System.Reflection;
+using System.Runtime.InteropServices;
 
 using TestLibrary;
 
@@ -13,8 +14,7 @@ unsafe internal class CheckGCMode
     {
         // GetIsInCooperativeGCModeFunctionPointer is conditionally included based on the runtime build configuration,
         // so we check for its existence and only do the explicit mode validation if it is available.
-        Type marshalType = typeof(object).Assembly.GetType(typeof(System.Runtime.InteropServices.Marshal).FullName);
-        MethodInfo getFunctionPtr = marshalType.GetMethod("GetIsInCooperativeGCModeFunctionPointer", BindingFlags.NonPublic | BindingFlags.Static);
+        MethodInfo getFunctionPtr = typeof(Marshal).GetMethod("GetIsInCooperativeGCModeFunctionPointer", BindingFlags.NonPublic | BindingFlags.Static);
         if (getFunctionPtr != null)
         {
             var isInCooperativeModeFunc = (delegate* unmanaged<int>)(IntPtr)getFunctionPtr.Invoke(null, null);