diff --git a/src/libraries/Microsoft.Win32.Registry/ref/Microsoft.Win32.Registry.cs b/src/libraries/Microsoft.Win32.Registry/ref/Microsoft.Win32.Registry.cs
index 81462eb9b7d69c..00cd1a2f643e99 100644
--- a/src/libraries/Microsoft.Win32.Registry/ref/Microsoft.Win32.Registry.cs
+++ b/src/libraries/Microsoft.Win32.Registry/ref/Microsoft.Win32.Registry.cs
@@ -15,9 +15,9 @@ public static partial class Registry
public static readonly Microsoft.Win32.RegistryKey LocalMachine;
public static readonly Microsoft.Win32.RegistryKey PerformanceData;
public static readonly Microsoft.Win32.RegistryKey Users;
- public static object GetValue(string keyName, string valueName, object defaultValue) { throw null; }
- public static void SetValue(string keyName, string valueName, object value) { }
- public static void SetValue(string keyName, string valueName, object value, Microsoft.Win32.RegistryValueKind valueKind) { }
+ public static object? GetValue(string keyName, string? valueName, object? defaultValue) { throw null; }
+ public static void SetValue(string keyName, string? valueName, object value) { }
+ public static void SetValue(string keyName, string? valueName, object value, Microsoft.Win32.RegistryValueKind valueKind) { }
}
public enum RegistryHive
{
@@ -40,8 +40,8 @@ public void Close() { }
public Microsoft.Win32.RegistryKey CreateSubKey(string subkey) { throw null; }
public Microsoft.Win32.RegistryKey CreateSubKey(string subkey, Microsoft.Win32.RegistryKeyPermissionCheck permissionCheck) { throw null; }
public Microsoft.Win32.RegistryKey CreateSubKey(string subkey, Microsoft.Win32.RegistryKeyPermissionCheck permissionCheck, Microsoft.Win32.RegistryOptions registryOptions) { throw null; }
- public Microsoft.Win32.RegistryKey CreateSubKey(string subkey, Microsoft.Win32.RegistryKeyPermissionCheck permissionCheck, Microsoft.Win32.RegistryOptions registryOptions, System.Security.AccessControl.RegistrySecurity registrySecurity) { throw null; }
- public Microsoft.Win32.RegistryKey CreateSubKey(string subkey, Microsoft.Win32.RegistryKeyPermissionCheck permissionCheck, System.Security.AccessControl.RegistrySecurity registrySecurity) { throw null; }
+ public Microsoft.Win32.RegistryKey CreateSubKey(string subkey, Microsoft.Win32.RegistryKeyPermissionCheck permissionCheck, Microsoft.Win32.RegistryOptions registryOptions, System.Security.AccessControl.RegistrySecurity? registrySecurity) { throw null; }
+ public Microsoft.Win32.RegistryKey CreateSubKey(string subkey, Microsoft.Win32.RegistryKeyPermissionCheck permissionCheck, System.Security.AccessControl.RegistrySecurity? registrySecurity) { throw null; }
public Microsoft.Win32.RegistryKey CreateSubKey(string subkey, bool writable) { throw null; }
public Microsoft.Win32.RegistryKey CreateSubKey(string subkey, bool writable, Microsoft.Win32.RegistryOptions options) { throw null; }
public void DeleteSubKey(string subkey) { }
@@ -57,22 +57,22 @@ public void Flush() { }
public System.Security.AccessControl.RegistrySecurity GetAccessControl() { throw null; }
public System.Security.AccessControl.RegistrySecurity GetAccessControl(System.Security.AccessControl.AccessControlSections includeSections) { throw null; }
public string[] GetSubKeyNames() { throw null; }
- public object GetValue(string name) { throw null; }
- public object GetValue(string name, object defaultValue) { throw null; }
- public object GetValue(string name, object defaultValue, Microsoft.Win32.RegistryValueOptions options) { throw null; }
- public Microsoft.Win32.RegistryValueKind GetValueKind(string name) { throw null; }
+ public object? GetValue(string? name) { throw null; }
+ public object? GetValue(string? name, object? defaultValue) { throw null; }
+ public object? GetValue(string? name, object? defaultValue, Microsoft.Win32.RegistryValueOptions options) { throw null; }
+ public Microsoft.Win32.RegistryValueKind GetValueKind(string? name) { throw null; }
public string[] GetValueNames() { throw null; }
public static Microsoft.Win32.RegistryKey OpenBaseKey(Microsoft.Win32.RegistryHive hKey, Microsoft.Win32.RegistryView view) { throw null; }
public static Microsoft.Win32.RegistryKey OpenRemoteBaseKey(Microsoft.Win32.RegistryHive hKey, string machineName) { throw null; }
public static Microsoft.Win32.RegistryKey OpenRemoteBaseKey(Microsoft.Win32.RegistryHive hKey, string machineName, Microsoft.Win32.RegistryView view) { throw null; }
- public Microsoft.Win32.RegistryKey OpenSubKey(string name) { throw null; }
- public Microsoft.Win32.RegistryKey OpenSubKey(string name, Microsoft.Win32.RegistryKeyPermissionCheck permissionCheck) { throw null; }
- public Microsoft.Win32.RegistryKey OpenSubKey(string name, Microsoft.Win32.RegistryKeyPermissionCheck permissionCheck, System.Security.AccessControl.RegistryRights rights) { throw null; }
- public Microsoft.Win32.RegistryKey OpenSubKey(string name, bool writable) { throw null; }
- public Microsoft.Win32.RegistryKey OpenSubKey(string name, System.Security.AccessControl.RegistryRights rights) { throw null; }
+ public Microsoft.Win32.RegistryKey? OpenSubKey(string name) { throw null; }
+ public Microsoft.Win32.RegistryKey? OpenSubKey(string name, Microsoft.Win32.RegistryKeyPermissionCheck permissionCheck) { throw null; }
+ public Microsoft.Win32.RegistryKey? OpenSubKey(string name, Microsoft.Win32.RegistryKeyPermissionCheck permissionCheck, System.Security.AccessControl.RegistryRights rights) { throw null; }
+ public Microsoft.Win32.RegistryKey? OpenSubKey(string name, bool writable) { throw null; }
+ public Microsoft.Win32.RegistryKey? OpenSubKey(string name, System.Security.AccessControl.RegistryRights rights) { throw null; }
public void SetAccessControl(System.Security.AccessControl.RegistrySecurity registrySecurity) { }
- public void SetValue(string name, object value) { }
- public void SetValue(string name, object value, Microsoft.Win32.RegistryValueKind valueKind) { }
+ public void SetValue(string? name, object value) { }
+ public void SetValue(string? name, object value, Microsoft.Win32.RegistryValueKind valueKind) { }
public override string ToString() { throw null; }
}
public enum RegistryKeyPermissionCheck
diff --git a/src/libraries/Microsoft.Win32.Registry/ref/Microsoft.Win32.Registry.csproj b/src/libraries/Microsoft.Win32.Registry/ref/Microsoft.Win32.Registry.csproj
index bece872888a28a..460ce738b8d0f2 100644
--- a/src/libraries/Microsoft.Win32.Registry/ref/Microsoft.Win32.Registry.csproj
+++ b/src/libraries/Microsoft.Win32.Registry/ref/Microsoft.Win32.Registry.csproj
@@ -2,6 +2,7 @@
true
netstandard2.0;$(NetFrameworkCurrent);net461
+ enable
diff --git a/src/libraries/Microsoft.Win32.Registry/src/Microsoft.Win32.Registry.csproj b/src/libraries/Microsoft.Win32.Registry/src/Microsoft.Win32.Registry.csproj
index bca5d38c61fb31..c477714db0b9f0 100644
--- a/src/libraries/Microsoft.Win32.Registry/src/Microsoft.Win32.Registry.csproj
+++ b/src/libraries/Microsoft.Win32.Registry/src/Microsoft.Win32.Registry.csproj
@@ -9,6 +9,7 @@
$(NetCoreAppCurrent)-Windows_NT;$(NetCoreAppCurrent)-Unix;$(NetFrameworkCurrent)-Windows_NT;netstandard2.0-Windows_NT;netstandard2.0-Unix;netstandard2.0;net461-Windows_NT
true
true
+ enable
@@ -107,4 +108,4 @@
-
\ No newline at end of file
+
diff --git a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/Registry.cs b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/Registry.cs
index f86f170333b897..803a1a6e694d0b 100644
--- a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/Registry.cs
+++ b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/Registry.cs
@@ -45,7 +45,7 @@ private static RegistryKey GetBaseKeyFromKeyName(string keyName, out string subK
int length = i != -1 ? i : keyName.Length;
// Determine the potential base key from the length.
- RegistryKey baseKey = null;
+ RegistryKey? baseKey = null;
switch (length)
{
case 10: baseKey = Users; break; // HKEY_USERS
@@ -68,28 +68,26 @@ private static RegistryKey GetBaseKeyFromKeyName(string keyName, out string subK
throw new ArgumentException(SR.Format(SR.Arg_RegInvalidKeyName, nameof(keyName)), nameof(keyName));
}
- public static object GetValue(string keyName, string valueName, object defaultValue)
+ public static object? GetValue(string keyName, string? valueName, object? defaultValue)
{
- string subKeyName;
- RegistryKey basekey = GetBaseKeyFromKeyName(keyName, out subKeyName);
+ RegistryKey basekey = GetBaseKeyFromKeyName(keyName, out string subKeyName);
- using (RegistryKey key = basekey.OpenSubKey(subKeyName))
+ using (RegistryKey? key = basekey.OpenSubKey(subKeyName))
{
return key?.GetValue(valueName, defaultValue);
}
}
- public static void SetValue(string keyName, string valueName, object value)
+ public static void SetValue(string keyName, string? valueName, object value)
{
SetValue(keyName, valueName, value, RegistryValueKind.Unknown);
}
- public static void SetValue(string keyName, string valueName, object value, RegistryValueKind valueKind)
+ public static void SetValue(string keyName, string? valueName, object value, RegistryValueKind valueKind)
{
- string subKeyName;
- RegistryKey basekey = GetBaseKeyFromKeyName(keyName, out subKeyName);
+ RegistryKey basekey = GetBaseKeyFromKeyName(keyName, out string subKeyName);
- using (RegistryKey key = basekey.CreateSubKey(subKeyName))
+ using (RegistryKey? key = basekey.CreateSubKey(subKeyName))
{
Debug.Assert(key != null, "An exception should be thrown if failed!");
key.SetValue(valueName, value, valueKind);
diff --git a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.FileSystem.cs b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.FileSystem.cs
index c0b9846ba4f232..6f0565adf93b73 100644
--- a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.FileSystem.cs
+++ b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.FileSystem.cs
@@ -92,17 +92,17 @@ private string[] GetValueNamesCore(int values)
throw new PlatformNotSupportedException(SR.PlatformNotSupported_Registry);
}
- private object InternalGetValueCore(string name, object defaultValue, bool doNotExpand)
+ private object InternalGetValueCore(string? name, object? defaultValue, bool doNotExpand)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_Registry);
}
- private RegistryValueKind GetValueKindCore(string name)
+ private RegistryValueKind GetValueKindCore(string? name)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_Registry);
}
- private void SetValueCore(string name, object value, RegistryValueKind valueKind)
+ private void SetValueCore(string? name, object value, RegistryValueKind valueKind)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_Registry);
}
diff --git a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.Windows.cs b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.Windows.cs
index 4cdde3b0730b7e..b55e1b2b5d9506 100644
--- a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.Windows.cs
+++ b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.Windows.cs
@@ -9,7 +9,6 @@
using System.Diagnostics;
using System.IO;
using System.Security;
-using System.Security.AccessControl;
/*
Note on transaction support:
@@ -85,11 +84,9 @@ private void FlushCore()
private unsafe RegistryKey CreateSubKeyInternalCore(string subkey, RegistryKeyPermissionCheck permissionCheck, RegistryOptions registryOptions)
{
- Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = default(Interop.Kernel32.SECURITY_ATTRIBUTES);
- int disposition = 0;
+ Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = default;
// By default, the new key will be writable.
- SafeRegistryHandle result = null;
int ret = Interop.Advapi32.RegCreateKeyEx(_hkey,
subkey,
0,
@@ -97,8 +94,8 @@ private unsafe RegistryKey CreateSubKeyInternalCore(string subkey, RegistryKeyPe
(int)registryOptions /* specifies if the key is volatile */,
GetRegistryKeyAccess(permissionCheck != RegistryKeyPermissionCheck.ReadSubTree) | (int)_regView,
ref secAttrs,
- out result,
- out disposition);
+ out SafeRegistryHandle result,
+ out int _);
if (ret == 0 && !result.IsInvalid)
{
@@ -220,8 +217,7 @@ private static RegistryKey OpenRemoteBaseKeyCore(RegistryHive hKey, string machi
}
// connect to the specified remote registry
- SafeRegistryHandle foreignHKey = null;
- int ret = Interop.Advapi32.RegConnectRegistry(machineName, new SafeRegistryHandle(new IntPtr((int)hKey), false), out foreignHKey);
+ int ret = Interop.Advapi32.RegConnectRegistry(machineName, new SafeRegistryHandle(new IntPtr((int)hKey), false), out SafeRegistryHandle foreignHKey);
if (ret == Interop.Errors.ERROR_DLL_INIT_FAILED)
{
@@ -246,10 +242,9 @@ private static RegistryKey OpenRemoteBaseKeyCore(RegistryHive hKey, string machi
return key;
}
- private RegistryKey InternalOpenSubKeyCore(string name, RegistryKeyPermissionCheck permissionCheck, int rights)
+ private RegistryKey? InternalOpenSubKeyCore(string name, RegistryKeyPermissionCheck permissionCheck, int rights)
{
- SafeRegistryHandle result = null;
- int ret = Interop.Advapi32.RegOpenKeyEx(_hkey, name, 0, (rights | (int)_regView), out result);
+ int ret = Interop.Advapi32.RegOpenKeyEx(_hkey, name, 0, (rights | (int)_regView), out SafeRegistryHandle result);
if (ret == 0 && !result.IsInvalid)
{
RegistryKey key = new RegistryKey(result, (permissionCheck == RegistryKeyPermissionCheck.ReadWriteSubTree), false, _remoteKey, false, _regView);
@@ -269,10 +264,9 @@ private RegistryKey InternalOpenSubKeyCore(string name, RegistryKeyPermissionChe
return null;
}
- private RegistryKey InternalOpenSubKeyCore(string name, bool writable)
+ private RegistryKey? InternalOpenSubKeyCore(string name, bool writable)
{
- SafeRegistryHandle result = null;
- int ret = Interop.Advapi32.RegOpenKeyEx(_hkey, name, 0, (GetRegistryKeyAccess(writable) | (int)_regView), out result);
+ int ret = Interop.Advapi32.RegOpenKeyEx(_hkey, name, 0, (GetRegistryKeyAccess(writable) | (int)_regView), out SafeRegistryHandle result);
if (ret == 0 && !result.IsInvalid)
{
RegistryKey key = new RegistryKey(result, writable, false, _remoteKey, false, _regView);
@@ -292,10 +286,9 @@ private RegistryKey InternalOpenSubKeyCore(string name, bool writable)
return null;
}
- internal RegistryKey InternalOpenSubKeyWithoutSecurityChecksCore(string name, bool writable)
+ internal RegistryKey? InternalOpenSubKeyWithoutSecurityChecksCore(string name, bool writable)
{
- SafeRegistryHandle result = null;
- int ret = Interop.Advapi32.RegOpenKeyEx(_hkey, name, 0, (GetRegistryKeyAccess(writable) | (int)_regView), out result);
+ int ret = Interop.Advapi32.RegOpenKeyEx(_hkey, name, 0, (GetRegistryKeyAccess(writable) | (int)_regView), out SafeRegistryHandle result);
if (ret == 0 && !result.IsInvalid)
{
RegistryKey key = new RegistryKey(result, writable, false, _remoteKey, false, _regView);
@@ -340,12 +333,11 @@ private SafeRegistryHandle SystemKeyHandle
}
// open the base key so that RegistryKey.Handle will return a valid handle
- SafeRegistryHandle result;
ret = Interop.Advapi32.RegOpenKeyEx(baseKey,
null,
0,
GetRegistryKeyAccess(IsWritable()) | (int)_regView,
- out result);
+ out SafeRegistryHandle result);
if (ret == 0 && !result.IsInvalid)
{
@@ -463,7 +455,7 @@ private unsafe string[] GetValueNamesCore(int values)
// add up quickly- we'll try to keep the memory pressure low and grow the buffer
// only if needed.
- char[] name = ArrayPool.Shared.Rent(100);
+ char[]? name = ArrayPool.Shared.Rent(100);
try
{
@@ -528,13 +520,13 @@ private unsafe string[] GetValueNamesCore(int values)
return names.ToArray();
}
- private object InternalGetValueCore(string name, object defaultValue, bool doNotExpand)
+ private object? InternalGetValueCore(string? name, object? defaultValue, bool doNotExpand)
{
- object data = defaultValue;
+ object? data = defaultValue;
int type = 0;
int datasize = 0;
- int ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, (byte[])null, ref datasize);
+ int ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, (byte[]?)null, ref datasize);
if (ret != 0)
{
@@ -734,7 +726,7 @@ private object InternalGetValueCore(string name, object defaultValue, bool doNot
nextNull++;
}
- string toAdd = null;
+ string? toAdd = null;
if (nextNull < len)
{
Debug.Assert(blob[nextNull] == (char)0, "blob[nextNull] should be 0");
@@ -780,11 +772,11 @@ private object InternalGetValueCore(string name, object defaultValue, bool doNot
return data;
}
- private RegistryValueKind GetValueKindCore(string name)
+ private RegistryValueKind GetValueKindCore(string? name)
{
int type = 0;
int datasize = 0;
- int ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, (byte[])null, ref datasize);
+ int ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, (byte[]?)null, ref datasize);
if (ret != 0)
{
Win32Error(ret, null);
@@ -796,7 +788,7 @@ private RegistryValueKind GetValueKindCore(string name)
(RegistryValueKind)type;
}
- private unsafe void SetValueCore(string name, object value, RegistryValueKind valueKind)
+ private unsafe void SetValueCore(string? name, object value, RegistryValueKind valueKind)
{
int ret = 0;
try
@@ -806,7 +798,7 @@ private unsafe void SetValueCore(string name, object value, RegistryValueKind va
case RegistryValueKind.ExpandString:
case RegistryValueKind.String:
{
- string data = value.ToString();
+ string data = value.ToString()!;
ret = Interop.Advapi32.RegSetValueEx(_hkey,
name,
0,
@@ -921,7 +913,7 @@ private unsafe void SetValueCore(string name, object value, RegistryValueKind va
/// error, and depending on the error, insert a string into the message
/// gotten from the ResourceManager.
///
- private void Win32Error(int errorCode, string str)
+ private void Win32Error(int errorCode, string? str)
{
switch (errorCode)
{
@@ -944,7 +936,7 @@ private void Win32Error(int errorCode, string str)
if (!IsPerfDataKey())
{
_hkey.SetHandleAsInvalid();
- _hkey = null;
+ _hkey = null!;
}
goto default;
@@ -956,7 +948,7 @@ private void Win32Error(int errorCode, string str)
}
}
- private static void Win32ErrorStatic(int errorCode, string str) =>
+ private static void Win32ErrorStatic(int errorCode, string? str) =>
throw errorCode switch
{
Interop.Errors.ERROR_ACCESS_DENIED => str != null ?
diff --git a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.cs b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.cs
index eaef0009a633e3..1860a0a2223ef6 100644
--- a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.cs
+++ b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.cs
@@ -113,7 +113,7 @@ public void Dispose()
}
finally
{
- _hkey = null;
+ _hkey = null!;
}
}
else if (IsPerfDataKey())
@@ -146,12 +146,12 @@ public RegistryKey CreateSubKey(string subkey, RegistryKeyPermissionCheck permis
return CreateSubKey(subkey, permissionCheck, RegistryOptions.None);
}
- public RegistryKey CreateSubKey(string subkey, RegistryKeyPermissionCheck permissionCheck, RegistryOptions registryOptions, RegistrySecurity registrySecurity)
+ public RegistryKey CreateSubKey(string subkey, RegistryKeyPermissionCheck permissionCheck, RegistryOptions registryOptions, RegistrySecurity? registrySecurity)
{
return CreateSubKey(subkey, permissionCheck, registryOptions);
}
- public RegistryKey CreateSubKey(string subkey, RegistryKeyPermissionCheck permissionCheck, RegistrySecurity registrySecurity)
+ public RegistryKey CreateSubKey(string subkey, RegistryKeyPermissionCheck permissionCheck, RegistrySecurity? registrySecurity)
{
return CreateSubKey(subkey, permissionCheck, RegistryOptions.None);
}
@@ -167,7 +167,7 @@ public RegistryKey CreateSubKey(string subkey, RegistryKeyPermissionCheck permis
// only keys opened under read mode is not writable
if (!_remoteKey)
{
- RegistryKey key = InternalOpenSubKeyWithoutSecurityChecks(subkey, (permissionCheck != RegistryKeyPermissionCheck.ReadSubTree));
+ RegistryKey? key = InternalOpenSubKeyWithoutSecurityChecks(subkey, (permissionCheck != RegistryKeyPermissionCheck.ReadSubTree));
if (key != null)
{
// Key already exits
@@ -199,7 +199,7 @@ public void DeleteSubKey(string subkey, bool throwOnMissingSubKey)
// Open the key we are deleting and check for children. Be sure to
// explicitly call close to avoid keeping an extra HKEY open.
//
- RegistryKey key = InternalOpenSubKeyWithoutSecurityChecks(subkey, false);
+ RegistryKey? key = InternalOpenSubKeyWithoutSecurityChecks(subkey, false);
if (key != null)
{
using (key)
@@ -243,7 +243,7 @@ public void DeleteSubKeyTree(string subkey, bool throwOnMissingSubKey)
subkey = FixupName(subkey); // Fixup multiple slashes to a single slash
- RegistryKey key = InternalOpenSubKeyWithoutSecurityChecks(subkey, true);
+ RegistryKey? key = InternalOpenSubKeyWithoutSecurityChecks(subkey, true);
if (key != null)
{
using (key)
@@ -273,7 +273,7 @@ public void DeleteSubKeyTree(string subkey, bool throwOnMissingSubKey)
///
private void DeleteSubKeyTreeInternal(string subkey)
{
- RegistryKey key = InternalOpenSubKeyWithoutSecurityChecks(subkey, true);
+ RegistryKey? key = InternalOpenSubKeyWithoutSecurityChecks(subkey, true);
if (key != null)
{
using (key)
@@ -338,7 +338,7 @@ public static RegistryKey OpenRemoteBaseKey(RegistryHive hKey, string machineNam
/// Returns a subkey with read only permissions.
/// Name or path of subkey to open.
/// The Subkey requested, or null if the operation failed.
- public RegistryKey OpenSubKey(string name)
+ public RegistryKey? OpenSubKey(string name)
{
return OpenSubKey(name, false);
}
@@ -350,7 +350,7 @@ public RegistryKey OpenSubKey(string name)
/// Name or the path of subkey to open.
/// Set to true if you only need readonly access.
/// the Subkey requested, or null if the operation failed.
- public RegistryKey OpenSubKey(string name, bool writable)
+ public RegistryKey? OpenSubKey(string name, bool writable)
{
ValidateKeyName(name);
EnsureNotDisposed();
@@ -359,19 +359,19 @@ public RegistryKey OpenSubKey(string name, bool writable)
return InternalOpenSubKeyCore(name, writable);
}
- public RegistryKey OpenSubKey(string name, RegistryKeyPermissionCheck permissionCheck)
+ public RegistryKey? OpenSubKey(string name, RegistryKeyPermissionCheck permissionCheck)
{
ValidateKeyMode(permissionCheck);
return OpenSubKey(name, permissionCheck, (RegistryRights)GetRegistryKeyAccess(permissionCheck));
}
- public RegistryKey OpenSubKey(string name, RegistryRights rights)
+ public RegistryKey? OpenSubKey(string name, RegistryRights rights)
{
return OpenSubKey(name, this._checkMode, rights);
}
- public RegistryKey OpenSubKey(string name, RegistryKeyPermissionCheck permissionCheck, RegistryRights rights)
+ public RegistryKey? OpenSubKey(string name, RegistryKeyPermissionCheck permissionCheck, RegistryRights rights)
{
ValidateKeyName(name);
ValidateKeyMode(permissionCheck);
@@ -384,7 +384,7 @@ public RegistryKey OpenSubKey(string name, RegistryKeyPermissionCheck permission
return InternalOpenSubKeyCore(name, permissionCheck, (int)rights);
}
- internal RegistryKey InternalOpenSubKeyWithoutSecurityChecks(string name, bool writable)
+ internal RegistryKey? InternalOpenSubKeyWithoutSecurityChecks(string name, bool writable)
{
ValidateKeyName(name);
EnsureNotDisposed();
@@ -497,7 +497,7 @@ public string[] GetValueNames()
///
/// Name of value to retrieve.
/// The data associated with the value.
- public object GetValue(string name)
+ public object? GetValue(string? name)
{
return InternalGetValue(name, null, false);
}
@@ -514,12 +514,12 @@ public object GetValue(string name)
/// Name of value to retrieve.
/// Value to return if name doesn't exist.
/// The data associated with the value.
- public object GetValue(string name, object defaultValue)
+ public object? GetValue(string? name, object? defaultValue)
{
return InternalGetValue(name, defaultValue, false);
}
- public object GetValue(string name, object defaultValue, RegistryValueOptions options)
+ public object? GetValue(string? name, object? defaultValue, RegistryValueOptions options)
{
if (options < RegistryValueOptions.None || options > RegistryValueOptions.DoNotExpandEnvironmentNames)
{
@@ -529,13 +529,13 @@ public object GetValue(string name, object defaultValue, RegistryValueOptions op
return InternalGetValue(name, defaultValue, doNotExpand);
}
- private object InternalGetValue(string name, object defaultValue, bool doNotExpand)
+ private object? InternalGetValue(string? name, object? defaultValue, bool doNotExpand)
{
EnsureNotDisposed();
return InternalGetValueCore(name, defaultValue, doNotExpand);
}
- public RegistryValueKind GetValueKind(string name)
+ public RegistryValueKind GetValueKind(string? name)
{
EnsureNotDisposed();
return GetValueKindCore(name);
@@ -553,12 +553,12 @@ public string Name
/// Sets the specified value.
/// Name of value to store data in.
/// Data to store.
- public void SetValue(string name, object value)
+ public void SetValue(string? name, object value)
{
SetValue(name, value, RegistryValueKind.Unknown);
}
- public void SetValue(string name, object value, RegistryValueKind valueKind)
+ public void SetValue(string? name, object value, RegistryValueKind valueKind)
{
if (value == null)
{
diff --git a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKeyPermissionCheck.cs b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKeyPermissionCheck.cs
index 92b8b0156c0d4f..f69b6eeb9bd185 100644
--- a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKeyPermissionCheck.cs
+++ b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKeyPermissionCheck.cs
@@ -2,8 +2,6 @@
// 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;
-
namespace Microsoft.Win32
{
public enum RegistryKeyPermissionCheck
@@ -11,5 +9,5 @@ public enum RegistryKeyPermissionCheck
Default = 0,
ReadSubTree = 1,
ReadWriteSubTree = 2,
- };
+ }
}
diff --git a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryOptions.cs b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryOptions.cs
index 112efd26e9a986..e288412b28107a 100644
--- a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryOptions.cs
+++ b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryOptions.cs
@@ -11,5 +11,5 @@ public enum RegistryOptions
{
None = Interop.Advapi32.RegistryOptions.REG_OPTION_NON_VOLATILE, // 0x0000
Volatile = Interop.Advapi32.RegistryOptions.REG_OPTION_VOLATILE, // 0x0001
- };
+ }
}
diff --git a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryView.cs b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryView.cs
index 0bfe1a53eb25ce..22b153ce05297b 100644
--- a/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryView.cs
+++ b/src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryView.cs
@@ -2,8 +2,6 @@
// 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;
-
namespace Microsoft.Win32
{
public enum RegistryView
@@ -11,5 +9,5 @@ public enum RegistryView
Default = 0, // 0x0000 operate on the default registry view
Registry64 = Interop.Advapi32.RegistryView.KEY_WOW64_64KEY, // 0x0100 operate on the 64-bit registry view
Registry32 = Interop.Advapi32.RegistryView.KEY_WOW64_32KEY, // 0x0200 operate on the 32-bit registry view
- };
+ }
}
diff --git a/src/libraries/Microsoft.Win32.Registry/src/System/Security/AccessControl/RegistryRights.cs b/src/libraries/Microsoft.Win32.Registry/src/System/Security/AccessControl/RegistryRights.cs
index 61e537159ec682..4e5de446385239 100644
--- a/src/libraries/Microsoft.Win32.Registry/src/System/Security/AccessControl/RegistryRights.cs
+++ b/src/libraries/Microsoft.Win32.Registry/src/System/Security/AccessControl/RegistryRights.cs
@@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using Microsoft.Win32;
-
namespace System.Security.AccessControl
{
// We derived this enum from the definitions of KEY_READ and such from
diff --git a/src/libraries/Microsoft.Win32.Registry/src/System/Security/AccessControl/RegistrySecurity.FileSystem.cs b/src/libraries/Microsoft.Win32.Registry/src/System/Security/AccessControl/RegistrySecurity.FileSystem.cs
index d41a07e98f6efd..2c81aaa32a21cc 100644
--- a/src/libraries/Microsoft.Win32.Registry/src/System/Security/AccessControl/RegistrySecurity.FileSystem.cs
+++ b/src/libraries/Microsoft.Win32.Registry/src/System/Security/AccessControl/RegistrySecurity.FileSystem.cs
@@ -8,7 +8,7 @@ namespace System.Security.AccessControl
{
public sealed partial class RegistrySecurity : NativeObjectSecurity
{
- private static Exception _HandleErrorCodeCore(int errorCode, string name, SafeHandle handle, object context)
+ private static Exception _HandleErrorCodeCore(int errorCode, string? name, SafeHandle? handle, object? context)
{
// TODO: Implement this
throw new PlatformNotSupportedException();
diff --git a/src/libraries/Microsoft.Win32.Registry/src/System/Security/AccessControl/RegistrySecurity.Windows.cs b/src/libraries/Microsoft.Win32.Registry/src/System/Security/AccessControl/RegistrySecurity.Windows.cs
index 240a1c2bed9356..5bcdd7a464c107 100644
--- a/src/libraries/Microsoft.Win32.Registry/src/System/Security/AccessControl/RegistrySecurity.Windows.cs
+++ b/src/libraries/Microsoft.Win32.Registry/src/System/Security/AccessControl/RegistrySecurity.Windows.cs
@@ -9,9 +9,9 @@ namespace System.Security.AccessControl
{
public sealed partial class RegistrySecurity : NativeObjectSecurity
{
- private static Exception _HandleErrorCodeCore(int errorCode, string name, SafeHandle handle, object context)
+ private static Exception? _HandleErrorCodeCore(int errorCode, string? name, SafeHandle? handle, object? context)
{
- Exception exception = null;
+ Exception? exception = null;
switch (errorCode)
{
diff --git a/src/libraries/Microsoft.Win32.Registry/src/System/Security/AccessControl/RegistrySecurity.cs b/src/libraries/Microsoft.Win32.Registry/src/System/Security/AccessControl/RegistrySecurity.cs
index fd8f244dfb83c7..4a3ad7a8985323 100644
--- a/src/libraries/Microsoft.Win32.Registry/src/System/Security/AccessControl/RegistrySecurity.cs
+++ b/src/libraries/Microsoft.Win32.Registry/src/System/Security/AccessControl/RegistrySecurity.cs
@@ -95,7 +95,7 @@ internal RegistrySecurity(SafeRegistryHandle hKey, string name, AccessControlSec
{
}
- private static Exception _HandleErrorCode(int errorCode, string name, SafeHandle handle, object context)
+ private static Exception? _HandleErrorCode(int errorCode, string? name, SafeHandle? handle, object? context)
{
return _HandleErrorCodeCore(errorCode, name, handle, context);
}