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 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 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 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
int disposition = 0;
// By default, the new key will be writable.
- SafeRegistryHandle result = null;
- int ret = Interop.Advapi32.RegCreateKeyEx(_hkey,
+ int ret = Interop.Advapi32.RegCreateKeyEx(_hkey!,
subkey,
0,
null,
(int)registryOptions /* specifies if the key is volatile */,
GetRegistryKeyAccess(permissionCheck != RegistryKeyPermissionCheck.ReadSubTree) | (int)_regView,
ref secAttrs,
- out result,
+ out SafeRegistryHandle result,
out disposition);
if (ret == 0 && !result.IsInvalid)
private void DeleteSubKeyCore(string subkey, bool throwOnMissingSubKey)
{
- int ret = Interop.Advapi32.RegDeleteKeyEx(_hkey, subkey, (int)_regView, 0);
+ int ret = Interop.Advapi32.RegDeleteKeyEx(_hkey!, subkey, (int)_regView, 0);
if (ret != 0)
{
private void DeleteSubKeyTreeCore(string subkey)
{
- int ret = Interop.Advapi32.RegDeleteKeyEx(_hkey, subkey, (int)_regView, 0);
+ int ret = Interop.Advapi32.RegDeleteKeyEx(_hkey!, subkey, (int)_regView, 0);
if (ret != 0)
{
Win32Error(ret, null);
private void DeleteValueCore(string name, bool throwOnMissingValue)
{
- int errorCode = Interop.Advapi32.RegDeleteValue(_hkey, name);
+ int errorCode = Interop.Advapi32.RegDeleteValue(_hkey!, name);
//
// From windows 2003 server, if the name is too long we will get error code ERROR_FILENAME_EXCED_RANGE
}
// 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)
{
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);
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);
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);
{
int subkeys = 0;
int junk = 0;
- int ret = Interop.Advapi32.RegQueryInfoKey(_hkey,
+ int ret = Interop.Advapi32.RegQueryInfoKey(_hkey!,
null,
null,
IntPtr.Zero,
int nameLength = name.Length;
while ((result = Interop.Advapi32.RegEnumKeyEx(
- _hkey,
+ _hkey!,
names.Count,
name,
ref nameLength,
{
int values = 0;
int junk = 0;
- int ret = Interop.Advapi32.RegQueryInfoKey(_hkey,
+ int ret = Interop.Advapi32.RegQueryInfoKey(_hkey!,
null,
null,
IntPtr.Zero,
// add up quickly- we'll try to keep the memory pressure low and grow the buffer
// only if needed.
- char[] name = ArrayPool<char>.Shared.Rent(100);
+ char[]? name = ArrayPool<char>.Shared.Rent(100);
try
{
int nameLength = name.Length;
while ((result = Interop.Advapi32.RegEnumValue(
- _hkey,
+ _hkey!,
names.Count,
name,
ref nameLength,
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)
{
int r;
byte[] blob = new byte[size];
- while (Interop.Errors.ERROR_MORE_DATA == (r = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, blob, ref sizeInput)))
+ while (Interop.Errors.ERROR_MORE_DATA == (r = Interop.Advapi32.RegQueryValueEx(_hkey!, name, null, ref type, blob, ref sizeInput)))
{
if (size == int.MaxValue)
{
case Interop.Advapi32.RegistryValues.REG_BINARY:
{
byte[] blob = new byte[datasize];
- ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, blob, ref datasize);
+ ret = Interop.Advapi32.RegQueryValueEx(_hkey!, name, null, ref type, blob, ref datasize);
data = blob;
}
break;
long blob = 0;
Debug.Assert(datasize == 8, "datasize==8");
// Here, datasize must be 8 when calling this
- ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, ref blob, ref datasize);
+ ret = Interop.Advapi32.RegQueryValueEx(_hkey!, name, null, ref type, ref blob, ref datasize);
data = blob;
}
int blob = 0;
Debug.Assert(datasize == 4, "datasize==4");
// Here, datasize must be four when calling this
- ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, ref blob, ref datasize);
+ ret = Interop.Advapi32.RegQueryValueEx(_hkey!, name, null, ref type, ref blob, ref datasize);
data = blob;
}
}
char[] blob = new char[datasize / 2];
- ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, blob, ref datasize);
+ ret = Interop.Advapi32.RegQueryValueEx(_hkey!, name, null, ref type, blob, ref datasize);
if (blob.Length > 0 && blob[blob.Length - 1] == (char)0)
{
data = new string(blob, 0, blob.Length - 1);
}
char[] blob = new char[datasize / 2];
- ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, blob, ref datasize);
+ ret = Interop.Advapi32.RegQueryValueEx(_hkey!, name, null, ref type, blob, ref datasize);
if (blob.Length > 0 && blob[blob.Length - 1] == (char)0)
{
}
char[] blob = new char[datasize / 2];
- ret = Interop.Advapi32.RegQueryValueEx(_hkey, name, null, ref type, blob, ref datasize);
+ ret = Interop.Advapi32.RegQueryValueEx(_hkey!, name, null, ref type, blob, ref datasize);
// make sure the string is null terminated before processing the data
if (blob.Length > 0 && blob[blob.Length - 1] != (char)0)
nextNull++;
}
- string toAdd = null;
+ string? toAdd = null;
if (nextNull < len)
{
Debug.Assert(blob[nextNull] == (char)0, "blob[nextNull] should be 0");
{
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);
(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
case RegistryValueKind.ExpandString:
case RegistryValueKind.String:
{
- string data = value.ToString();
- ret = Interop.Advapi32.RegSetValueEx(_hkey,
+ string data = value.ToString()!;
+ ret = Interop.Advapi32.RegSetValueEx(_hkey!,
name,
0,
(int)valueKind,
destinationIndex += (length + 1); // +1 for null terminator, which is already zero-initialized in new array.
}
- ret = Interop.Advapi32.RegSetValueEx(_hkey,
+ ret = Interop.Advapi32.RegSetValueEx(_hkey!,
name,
0,
Interop.Advapi32.RegistryValues.REG_MULTI_SZ,
case RegistryValueKind.None:
case RegistryValueKind.Binary:
byte[] dataBytes = (byte[])value;
- ret = Interop.Advapi32.RegSetValueEx(_hkey,
+ ret = Interop.Advapi32.RegSetValueEx(_hkey!,
name,
0,
(valueKind == RegistryValueKind.None ? Interop.Advapi32.RegistryValues.REG_NONE : Interop.Advapi32.RegistryValues.REG_BINARY),
// unboxed and cast at the same time. I.e. ((int)(object)(short) 5) will fail.
int data = Convert.ToInt32(value, System.Globalization.CultureInfo.InvariantCulture);
- ret = Interop.Advapi32.RegSetValueEx(_hkey,
+ ret = Interop.Advapi32.RegSetValueEx(_hkey!,
name,
0,
Interop.Advapi32.RegistryValues.REG_DWORD,
{
long data = Convert.ToInt64(value, System.Globalization.CultureInfo.InvariantCulture);
- ret = Interop.Advapi32.RegSetValueEx(_hkey,
+ ret = Interop.Advapi32.RegSetValueEx(_hkey!,
name,
0,
Interop.Advapi32.RegistryValues.REG_QWORD,
/// error, and depending on the error, insert a string into the message
/// gotten from the ResourceManager.
/// </summary>
- private void Win32Error(int errorCode, string str)
+ private void Win32Error(int errorCode, string? str)
{
switch (errorCode)
{
// having serialized access).
if (!IsPerfDataKey())
{
- _hkey.SetHandleAsInvalid();
+ _hkey!.SetHandleAsInvalid();
_hkey = null;
}
goto default;
}
}
- 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 ?
private const int MaxKeyLength = 255;
private const int MaxValueLength = 16383;
- private volatile SafeRegistryHandle _hkey;
+ private volatile SafeRegistryHandle? _hkey;
private volatile string _keyName;
private readonly bool _remoteKey;
private volatile StateFlags _state;
// 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
// 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)
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)
/// </summary>
private void DeleteSubKeyTreeInternal(string subkey)
{
- RegistryKey key = InternalOpenSubKeyWithoutSecurityChecks(subkey, true);
+ RegistryKey? key = InternalOpenSubKeyWithoutSecurityChecks(subkey, true);
if (key != null)
{
using (key)
/// <summary>Returns a subkey with read only permissions.</summary>
/// <param name="name">Name or path of subkey to open.</param>
/// <returns>The Subkey requested, or <b>null</b> if the operation failed.</returns>
- public RegistryKey OpenSubKey(string name)
+ public RegistryKey? OpenSubKey(string name)
{
return OpenSubKey(name, false);
}
/// <param name="name">Name or the path of subkey to open.</param>
/// <param name="writable">Set to <b>true</b> if you only need readonly access.</param>
/// <returns>the Subkey requested, or <b>null</b> if the operation failed.</returns>
- public RegistryKey OpenSubKey(string name, bool writable)
+ public RegistryKey? OpenSubKey(string name, bool writable)
{
ValidateKeyName(name);
EnsureNotDisposed();
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);
return InternalOpenSubKeyCore(name, permissionCheck, (int)rights);
}
- internal RegistryKey InternalOpenSubKeyWithoutSecurityChecks(string name, bool writable)
+ internal RegistryKey? InternalOpenSubKeyWithoutSecurityChecks(string name, bool writable)
{
ValidateKeyName(name);
EnsureNotDisposed();
get
{
EnsureNotDisposed();
- return IsSystemKey() ? SystemKeyHandle : _hkey;
+ return IsSystemKey() ? SystemKeyHandle : _hkey!;
}
}
/// </remarks>
/// <param name="name">Name of value to retrieve.</param>
/// <returns>The data associated with the value.</returns>
- public object GetValue(string name)
+ public object? GetValue(string? name)
{
return InternalGetValue(name, null, false);
}
/// <param name="name">Name of value to retrieve.</param>
/// <param name="defaultValue">Value to return if <i>name</i> doesn't exist.</param>
/// <returns>The data associated with the value.</returns>
- 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)
{
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);
/// <summary>Sets the specified value.</summary>
/// <param name="name">Name of value to store data in.</param>
/// <param name="value">Data to store.</param>
- 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)
{