moved to shared (#19419)
authorAnirudh Agnihotry <anirudhagnihotry098@gmail.com>
Sat, 11 Aug 2018 07:31:01 +0000 (00:31 -0700)
committerGitHub <noreply@github.com>
Sat, 11 Aug 2018 07:31:01 +0000 (00:31 -0700)
src/System.Private.CoreLib/System.Private.CoreLib.csproj
src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegCloseKey.cs [new file with mode: 0644]
src/System.Private.CoreLib/shared/Interop/Windows/Interop.Libraries.cs
src/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs [new file with mode: 0644]
src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems
src/System.Private.CoreLib/src/Microsoft/Win32/RegistryKey.cs
src/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs [deleted file]

index 73819e1e4fcab1479db86eb31298ec78577d87a6..70c5749105058b540dbf99a8b890e6b644d7de69 100644 (file)
     <Compile Include="$(BclSourcesRoot)\System\Collections\Generic\ArraySortHelper.CoreCLR.cs" />
     <Compile Include="$(BclSourcesRoot)\System\Collections\ObjectModel\ReadOnlyDictionary.cs" />
   </ItemGroup>
-  <ItemGroup>
-    <Compile Condition="'$(FeatureWin32Registry)' == 'true'" Include="$(BclSourcesRoot)\Microsoft\Win32\SafeHandles\SafeRegistryHandle.cs" />
-  </ItemGroup>
   <ItemGroup>
     <Compile Include="$(BclSourcesRoot)\System\Numerics\Hashing\HashHelpers.cs" />
   </ItemGroup>
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegCloseKey.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Advapi32/Interop.RegCloseKey.cs
new file mode 100644 (file)
index 0000000..375376d
--- /dev/null
@@ -0,0 +1,15 @@
+// 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.
+
+using System;
+using System.Runtime.InteropServices;
+
+internal partial class Interop
+{
+    internal partial class Advapi32
+    {
+        [DllImport(Libraries.Advapi32)]
+        internal static extern int RegCloseKey(IntPtr hKey);
+    }
+}
index 45d910bfcc78f8bfd1416d97ecc9ae81786dcb19..7b77d2dad36094470e5bab749d583717901bfa6e 100644 (file)
@@ -6,6 +6,7 @@ internal static partial class Interop
 {
     internal static partial class Libraries
     {
+        internal const string Advapi32 = "advapi32.dll";
         internal const string BCrypt = "BCrypt.dll";
         internal const string Crypt32 = "crypt32.dll";
         internal const string Kernel32 = "kernel32.dll";
diff --git a/src/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs b/src/System.Private.CoreLib/shared/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs
new file mode 100644 (file)
index 0000000..a3132ae
--- /dev/null
@@ -0,0 +1,33 @@
+// 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.
+
+using System;
+using System.Security;
+using System.Runtime.InteropServices;
+using System.Runtime.CompilerServices;
+using System.Runtime.ConstrainedExecution;
+using System.Runtime.Versioning;
+
+namespace Microsoft.Win32.SafeHandles
+{
+#if REGISTRY_ASSEMBLY
+    public
+#else
+    internal
+#endif
+    sealed class SafeRegistryHandle : SafeHandleZeroOrMinusOneIsInvalid
+    {
+        internal SafeRegistryHandle() : base(true) { }
+
+        public SafeRegistryHandle(IntPtr preexistingHandle, bool ownsHandle) : base(ownsHandle)
+        {
+            SetHandle(preexistingHandle);
+        }
+
+        protected override bool ReleaseHandle()
+        {
+            return (Interop.Advapi32.RegCloseKey(handle) == Interop.Errors.ERROR_SUCCESS);
+        }
+    }
+}
index 1133ce5954acb34d4ba338f0b241e62d4308eada..e002a3577301fab3c0d550fba44ef859629033b0 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.Win32.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\TimeZoneInfo.Win32.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeLibraryHandle.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)\Microsoft\Win32\SafeHandles\SafeRegistryHandle.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.LoadLibraryEx.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.FreeLibrary.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.CreateFile.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.MUI.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Advapi32\Interop.RegCloseKey.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\Kernel32\Interop.TimeZone.Registry.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\User32\Interop.Constants.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Interop\Windows\User32\Interop.SendMessageTimeout.cs" />
index 28f86f35ddb119456f7f66fcf078221f942dcee8..69ac1cd039a204b5d35623fe4a04d3b6061c1160 100644 (file)
@@ -248,7 +248,7 @@ namespace Microsoft.Win32
                     // the dispose below and usage elsewhere (other threads). This is By Design. 
                     // This is less of an issue when OS > NT5 (i.e Vista & higher), we can close the perfkey  
                     // (to release & refresh PERFLIB resources) and the OS will rebuild PERFLIB as necessary. 
-                    SafeRegistryHandle.RegCloseKey(RegistryKey.HKEY_PERFORMANCE_DATA);
+                    Interop.Advapi32.RegCloseKey(RegistryKey.HKEY_PERFORMANCE_DATA);
                 }
             }
         }
diff --git a/src/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs b/src/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeRegistryHandle.cs
deleted file mode 100644 (file)
index b69bc42..0000000
+++ /dev/null
@@ -1,39 +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.
-
-//
-//
-//
-// Implements Microsoft.Win32.SafeHandles.SafeRegistryHandle
-//
-// ======================================================================================
-
-using System;
-using System.Security;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-using System.Runtime.ConstrainedExecution;
-using System.Runtime.Versioning;
-
-namespace Microsoft.Win32.SafeHandles
-{
-    internal sealed class SafeRegistryHandle : SafeHandleZeroOrMinusOneIsInvalid
-    {
-        internal SafeRegistryHandle() : base(true) { }
-
-        public SafeRegistryHandle(IntPtr preexistingHandle, bool ownsHandle) : base(ownsHandle)
-        {
-            SetHandle(preexistingHandle);
-        }
-
-        override protected bool ReleaseHandle()
-        {
-            return (RegCloseKey(handle) == Interop.Errors.ERROR_SUCCESS);
-        }
-
-        [DllImport(Win32Native.ADVAPI32)]
-        internal static extern int RegCloseKey(IntPtr hKey);
-    }
-}
-