From 3c37719c800f690f1acfab204fc0477f5932d0f1 Mon Sep 17 00:00:00 2001 From: clown Date: Tue, 26 Jul 2022 14:08:12 +0900 Subject: [PATCH] rename DefaultKey to RootRegistryKey. --- Libraries/Core/Sources/DataContract/Proxy.cs | 21 ++++++++++--------- .../Sources/Internal/RegistryFixture.cs | 6 +++--- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Libraries/Core/Sources/DataContract/Proxy.cs b/Libraries/Core/Sources/DataContract/Proxy.cs index 03fb9dd9..32d18319 100644 --- a/Libraries/Core/Sources/DataContract/Proxy.cs +++ b/Libraries/Core/Sources/DataContract/Proxy.cs @@ -21,6 +21,7 @@ namespace Cube.DataContract; using System.Runtime.Serialization; using System.Runtime.Serialization.Json; using System.Text; +using System.Threading; using System.Xml; using Cube.FileSystem; using Microsoft.Win32; @@ -41,10 +42,10 @@ public static class Proxy /* --------------------------------------------------------------------- */ /// - /// DefaultKey + /// RootRegistryKey /// /// - /// Gets or sets the default registry subkey when serializing or + /// Gets or sets the root registry subkey when serializing or /// deserializing the registry. /// /// @@ -54,10 +55,10 @@ public static class Proxy /// /// /* --------------------------------------------------------------------- */ - public static RegistryKey DefaultKey + public static RegistryKey RootRegistryKey { - get => _defaultKey ??= Registry.CurrentUser.OpenSubKey("Software", true); - set => _defaultKey = value; + get => _root ??= Registry.CurrentUser.OpenSubKey("Software", true); + set => Interlocked.Exchange(ref _root, value)?.Dispose(); } #endregion @@ -88,7 +89,7 @@ public static void Serialize(this Format format, string dest, T src) IoEx.Save(dest, e => SerializeJson(e, src)); break; case Format.Registry: - using (var e = DefaultKey.CreateSubKey(dest)) Serialize(e, src); + using (var e = RootRegistryKey.CreateSubKey(dest)) Serialize(e, src); break; } } @@ -166,7 +167,7 @@ public static T Deserialize(this Format format, string src) case Format.Json: return IoEx.Load(src, e => (T)new DataContractJsonSerializer(typeof(T)).ReadObject(e)); case Format.Registry: - using (var e = DefaultKey.OpenSubKey(src, false)) return Deserialize(e); + using (var e = RootRegistryKey.OpenSubKey(src, false)) return Deserialize(e); } return default; } @@ -210,7 +211,7 @@ public static bool Exists(this Format format, string src) switch (format) { case Format.Registry: - using (var e = DefaultKey.OpenSubKey(src, false)) return e is not null; + using (var e = RootRegistryKey.OpenSubKey(src, false)) return e is not null; default: return Io.Exists(src); } @@ -233,7 +234,7 @@ public static void Delete(this Format format, string src) switch (format) { case Format.Registry: - DefaultKey.DeleteSubKeyTree(src, false); + RootRegistryKey.DeleteSubKeyTree(src, false); break; default: if (Io.Exists(src)) Io.Delete(src); @@ -244,6 +245,6 @@ public static void Delete(this Format format, string src) #endregion #region Fields - private static RegistryKey _defaultKey; + private static RegistryKey _root; #endregion } diff --git a/Tests/FileSystem/Sources/Internal/RegistryFixture.cs b/Tests/FileSystem/Sources/Internal/RegistryFixture.cs index 7991aac8..91f81fa6 100644 --- a/Tests/FileSystem/Sources/Internal/RegistryFixture.cs +++ b/Tests/FileSystem/Sources/Internal/RegistryFixture.cs @@ -95,7 +95,7 @@ class RegistryFixture : FileFixture /// /* --------------------------------------------------------------------- */ protected RegistryKey CreateSubKey(string subkey) => - Proxy.DefaultKey.CreateSubKey(GetKeyName(subkey)); + Proxy.RootRegistryKey.CreateSubKey(GetKeyName(subkey)); /* --------------------------------------------------------------------- */ /// @@ -107,7 +107,7 @@ protected RegistryKey CreateSubKey(string subkey) => /// /* --------------------------------------------------------------------- */ protected RegistryKey OpenSubKey(string subkey) => - Proxy.DefaultKey.OpenSubKey(GetKeyName(subkey), false); + Proxy.RootRegistryKey.OpenSubKey(GetKeyName(subkey), false); /* --------------------------------------------------------------------- */ /// @@ -161,7 +161,7 @@ protected virtual void Setup() /// /* --------------------------------------------------------------------- */ [TearDown] - protected override void Teardown() => Proxy.DefaultKey.DeleteSubKeyTree(Shared, false); + protected override void Teardown() => Proxy.RootRegistryKey.DeleteSubKeyTree(Shared, false); #endregion }