Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullable annotate for Microsoft.Win32.Registry #2351

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -37,13 +37,13 @@ internal RegistryKey() { }
public int ValueCount { get { throw null; } }
public Microsoft.Win32.RegistryView View { get { throw null; } }
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, bool writable) { throw null; }
public Microsoft.Win32.RegistryKey CreateSubKey(string subkey, bool writable, Microsoft.Win32.RegistryOptions options) { throw null; }
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, bool writable) { throw null; }
public Microsoft.Win32.RegistryKey? CreateSubKey(string subkey, bool writable, Microsoft.Win32.RegistryOptions options) { throw null; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per @eiriktsarpalis's comment https://github.com/dotnet/runtime/pull/2351/files#r378221011 all this CreateSubKey(...) overloads not return null

public void DeleteSubKey(string subkey) { }
public void DeleteSubKey(string subkey, bool throwOnMissingSubKey) { }
public void DeleteSubKeyTree(string subkey) { }
Expand All @@ -57,22 +57,22 @@ public void Flush() { }
public System.Security.AccessControl.RegistrySecurity GetAccessControl() { throw null; }
manne marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<IsPartialFacadeAssembly Condition="'$(TargetsNetFx)' == 'true'">true</IsPartialFacadeAssembly>
<TargetFrameworks>netstandard2.0;$(NetFrameworkCurrent);net461</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="Microsoft.Win32.Registry.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<IsPartialFacadeAssembly Condition="'$(TargetsNetFx)' == 'true'">true</IsPartialFacadeAssembly>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetsAnyOS)' == 'true' and '$(TargetsNetStandard)' == 'true'">SR.PlatformNotSupported_Registry</GeneratePlatformNotSupportedAssemblyMessage>
<NoWarn Condition="'$(TargetsUnix)' == 'true'">$(NoWarn);CA1823</NoWarn> <!-- Avoid unused fields warnings in Unix build -->
<Nullable>enable</Nullable>
<TargetFrameworks>netstandard2.0-Windows_NT;netstandard2.0-Unix;netstandard2.0;net461-Windows_NT;$(NetCoreAppCurrent)-Windows_NT;$(NetCoreAppCurrent)-Unix;$(NetFrameworkCurrent)-Windows_NT</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<ExcludeCurrentFullFrameworkFromPackage>true</ExcludeCurrentFullFrameworkFromPackage>
Expand Down Expand Up @@ -107,4 +108,4 @@
<Reference Include="System.Security.AccessControl" />
<Reference Include="System.Security.Principal.Windows" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading