Annotate Microsoft.Win32.Registry
authorManuel Pfemeter <manne@users.noreply.github.com>
Wed, 29 Jan 2020 20:11:10 +0000 (21:11 +0100)
committerManuel Pfemeter <m>
Tue, 11 Feb 2020 19:28:20 +0000 (20:28 +0100)
src/libraries/Microsoft.Win32.Registry/ref/Microsoft.Win32.Registry.cs
src/libraries/Microsoft.Win32.Registry/ref/Microsoft.Win32.Registry.csproj
src/libraries/Microsoft.Win32.Registry/src/Microsoft.Win32.Registry.csproj
src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/Registry.cs
src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.FileSystem.cs
src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.Windows.cs
src/libraries/Microsoft.Win32.Registry/src/Microsoft/Win32/RegistryKey.cs
src/libraries/Microsoft.Win32.Registry/src/System/Security/AccessControl/RegistrySecurity.Windows.cs
src/libraries/Microsoft.Win32.Registry/src/System/Security/AccessControl/RegistrySecurity.cs

index ca0e7ec..9cf053f 100644 (file)
@@ -15,7 +15,7 @@ namespace Microsoft.Win32
         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) { }
     }
@@ -57,22 +57,22 @@ namespace Microsoft.Win32
         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
index bece872..460ce73 100644 (file)
@@ -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" />
index 7acbbaf..4d67950 100644 (file)
@@ -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>
     <Reference Include="System.Security.AccessControl" />
     <Reference Include="System.Security.Principal.Windows" />
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
index f86f170..5e0a74c 100644 (file)
@@ -45,7 +45,7 @@ namespace Microsoft.Win32
             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
@@ -62,18 +62,18 @@ namespace Microsoft.Win32
                     string.Empty :
                     keyName.Substring(i + 1, keyName.Length - i - 1);
 
-                return baseKey;
+                return baseKey!;
             }
 
             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);
 
-            using (RegistryKey key = basekey.OpenSubKey(subKeyName))
+            using (RegistryKey? key = basekey.OpenSubKey(subKeyName))
             {
                 return key?.GetValue(valueName, defaultValue);
             }
index c0b9846..3a32fce 100644 (file)
@@ -92,7 +92,7 @@ namespace Microsoft.Win32
             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);
         }
@@ -102,7 +102,7 @@ namespace Microsoft.Win32
             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);
         }
index 4cdde3b..dc61af6 100644 (file)
@@ -89,15 +89,14 @@ namespace Microsoft.Win32
             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)
@@ -126,7 +125,7 @@ namespace Microsoft.Win32
 
         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)
             {
@@ -146,7 +145,7 @@ namespace Microsoft.Win32
 
         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);
@@ -155,7 +154,7 @@ namespace Microsoft.Win32
 
         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
@@ -220,8 +219,7 @@ namespace Microsoft.Win32
             }
 
             // 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 +244,9 @@ namespace Microsoft.Win32
             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 +266,9 @@ namespace Microsoft.Win32
             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 +288,9 @@ namespace Microsoft.Win32
             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);
@@ -363,7 +358,7 @@ namespace Microsoft.Win32
         {
             int subkeys = 0;
             int junk = 0;
-            int ret = Interop.Advapi32.RegQueryInfoKey(_hkey,
+            int ret = Interop.Advapi32.RegQueryInfoKey(_hkey!,
                                       null,
                                       null,
                                       IntPtr.Zero,
@@ -395,7 +390,7 @@ namespace Microsoft.Win32
                 int nameLength = name.Length;
 
                 while ((result = Interop.Advapi32.RegEnumKeyEx(
-                    _hkey,
+                    _hkey!,
                     names.Count,
                     name,
                     ref nameLength,
@@ -429,7 +424,7 @@ namespace Microsoft.Win32
         {
             int values = 0;
             int junk = 0;
-            int ret = Interop.Advapi32.RegQueryInfoKey(_hkey,
+            int ret = Interop.Advapi32.RegQueryInfoKey(_hkey!,
                                       null,
                                       null,
                                       IntPtr.Zero,
@@ -463,7 +458,7 @@ namespace Microsoft.Win32
             // 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
             {
@@ -471,7 +466,7 @@ namespace Microsoft.Win32
                 int nameLength = name.Length;
 
                 while ((result = Interop.Advapi32.RegEnumValue(
-                    _hkey,
+                    _hkey!,
                     names.Count,
                     name,
                     ref nameLength,
@@ -528,13 +523,13 @@ namespace Microsoft.Win32
             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)
             {
@@ -545,7 +540,7 @@ namespace Microsoft.Win32
 
                     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)
                         {
@@ -596,7 +591,7 @@ namespace Microsoft.Win32
                 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;
@@ -610,7 +605,7 @@ namespace Microsoft.Win32
                         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;
                     }
@@ -625,7 +620,7 @@ namespace Microsoft.Win32
                         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;
                     }
@@ -647,7 +642,7 @@ namespace Microsoft.Win32
                         }
                         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);
@@ -677,7 +672,7 @@ namespace Microsoft.Win32
                         }
                         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)
                         {
@@ -712,7 +707,7 @@ namespace Microsoft.Win32
                         }
                         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)
@@ -734,7 +729,7 @@ namespace Microsoft.Win32
                                 nextNull++;
                             }
 
-                            string toAdd = null;
+                            string? toAdd = null;
                             if (nextNull < len)
                             {
                                 Debug.Assert(blob[nextNull] == (char)0, "blob[nextNull] should be 0");
@@ -784,7 +779,7 @@ namespace Microsoft.Win32
         {
             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 +791,7 @@ namespace Microsoft.Win32
                 (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,8 +801,8 @@ namespace Microsoft.Win32
                     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,
@@ -849,7 +844,7 @@ namespace Microsoft.Win32
                                 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,
@@ -862,7 +857,7 @@ namespace Microsoft.Win32
                     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),
@@ -876,7 +871,7 @@ namespace Microsoft.Win32
                             // 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,
@@ -889,7 +884,7 @@ namespace Microsoft.Win32
                         {
                             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,
@@ -921,7 +916,7 @@ namespace Microsoft.Win32
         /// 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)
             {
@@ -943,7 +938,7 @@ namespace Microsoft.Win32
                     // having serialized access).
                     if (!IsPerfDataKey())
                     {
-                        _hkey.SetHandleAsInvalid();
+                        _hkey!.SetHandleAsInvalid();
                         _hkey = null;
                     }
                     goto default;
@@ -956,7 +951,7 @@ namespace Microsoft.Win32
             }
         }
 
-        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 ?
index eaef000..2b26d06 100644 (file)
@@ -41,7 +41,7 @@ namespace Microsoft.Win32
         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;
@@ -167,7 +167,7 @@ namespace Microsoft.Win32
             // 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 @@ namespace Microsoft.Win32
             // 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 @@ namespace Microsoft.Win32
 
             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 @@ namespace Microsoft.Win32
         /// </summary>
         private void DeleteSubKeyTreeInternal(string subkey)
         {
-            RegistryKey key = InternalOpenSubKeyWithoutSecurityChecks(subkey, true);
+            RegistryKey? key = InternalOpenSubKeyWithoutSecurityChecks(subkey, true);
             if (key != null)
             {
                 using (key)
@@ -338,7 +338,7 @@ namespace Microsoft.Win32
         /// <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);
         }
@@ -350,7 +350,7 @@ namespace Microsoft.Win32
         /// <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();
@@ -359,19 +359,19 @@ namespace Microsoft.Win32
             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 @@ namespace Microsoft.Win32
             return InternalOpenSubKeyCore(name, permissionCheck, (int)rights);
         }
 
-        internal RegistryKey InternalOpenSubKeyWithoutSecurityChecks(string name, bool writable)
+        internal RegistryKey? InternalOpenSubKeyWithoutSecurityChecks(string name, bool writable)
         {
             ValidateKeyName(name);
             EnsureNotDisposed();
@@ -439,7 +439,7 @@ namespace Microsoft.Win32
             get
             {
                 EnsureNotDisposed();
-                return IsSystemKey() ? SystemKeyHandle : _hkey;
+                return IsSystemKey() ? SystemKeyHandle : _hkey!;
             }
         }
 
@@ -497,7 +497,7 @@ namespace Microsoft.Win32
         /// </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);
         }
@@ -514,12 +514,12 @@ namespace Microsoft.Win32
         /// <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)
             {
@@ -529,7 +529,7 @@ namespace Microsoft.Win32
             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);
@@ -553,12 +553,12 @@ namespace Microsoft.Win32
         /// <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)
             {
index 240a1c2..8837f29 100644 (file)
@@ -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)
             {
index fd8f244..8861e75 100644 (file)
@@ -95,7 +95,7 @@ namespace System.Security.AccessControl
         {
         }
 
-        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);
         }