8000 Enable nullable: Microsoft.PowerShell.Commands.IRegistryWrapper by powercode · Pull Request #14177 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Enable nullable: Microsoft.PowerShell.Commands.IRegistryWrapper #14177

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

Merged
merged 2 commits into from
May 20, 2021
Merged
Changes from all 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
17 changes: 10 additions & 7 deletions src/System.Management.Automation/namespaces/RegistryWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,31 @@

namespace Microsoft.PowerShell.Commands
{

#nullable enable
internal interface IRegistryWrapper
{
void SetValue(string name, object value);
void SetValue(string? name, object value);

void SetValue(string name, object value, RegistryValueKind valueKind);
void SetValue(string? name, object value, RegistryValueKind valueKind);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does it mean to set a null-named key in the registry?

Copy link
Collaborator

Choose a reason for hiding this comment

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

From docs: https://docs.microsoft.com/en-us/dotnet/api/microsoft.win32.registrykey.setvalue?view=net-5.0#Microsoft_Win32_RegistryKey_SetValue_System_String_System_Object_

A registry key can have one value that is not associated with any name. When this unnamed value is displayed in the registry editor, the string "(Default)" appears instead of a name. To set this unnamed value, specify either null or the empty string ("") for name.


string[] GetValueNames();

void DeleteValue(string name);

string[] GetSubKeyNames();

IRegistryWrapper CreateSubKey(string subkey);
IRegistryWrapper? CreateSubKey(string subkey);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is null returned when create fails?

Copy link
Collaborator

Choose a reason for hiding this comment

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

From docs: https://docs.microsoft.com/en-us/dotnet/api/microsoft.win32.registrykey.createsubkey?view=net-5.0#Microsoft_Win32_RegistryKey_CreateSubKey_System_String_

Returns
RegistryKey
The newly created subkey, or null if the operation failed. If a zero-length string is specified for subkey, the current RegistryKey object is returned.


IRegistryWrapper OpenSubKey(string name, bool writable);
IRegistryWrapper? OpenSubKey(string name, bool writable);

void DeleteSubKeyTree(string subkey);

object GetValue(string name);
object? GetValue(string? name);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is null returned when the key doesn't exist?

Copy link
Collaborator

Choose a reason for hiding this comment

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


object GetValue(string name, object defaultValue, RegistryValueOptions options);
object? GetValue(string? name, object? defaultValue, RegistryValueOptions options);

RegistryValueKind GetValueKind(string name);
RegistryValueKind GetValueKind(string? name);

object RegistryKey { get; }

Expand All @@ -53,6 +55,7 @@ internal interface IRegistryWrapper

int SubKeyCount { get; }
}
#nullable restore

internal static class RegistryWrapperUtils
{
Expand Down
0