Wed Feb 24 15:47:16 CET 2010 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / corlib / Microsoft.Win32 / Registry.cs
index ca523d1cf23a7d0f413f9812950dffad8c0089e8..e5041ac28978396b892fbf0928a76ffee0297d1e 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+#if !NET_2_1
+
 using System;
+using System.Runtime.InteropServices;
 
 namespace Microsoft.Win32
 {
-       public
-#if NET_2_0
-       static
-#else
-       sealed
-#endif
-       class Registry
+       [ComVisible (true)]
+       public static class Registry
        {
-#if !NET_2_0
-               private Registry () { }
-#endif
                public static readonly RegistryKey ClassesRoot = new RegistryKey (
-                               RegistryHive.ClassesRoot, "HKEY_CLASSES_ROOT");
+                               RegistryHive.ClassesRoot);
                public static readonly RegistryKey CurrentConfig = new RegistryKey (
-                               RegistryHive.CurrentConfig, "HKEY_CURRENT_CONFIG");
+                               RegistryHive.CurrentConfig);
                public static readonly RegistryKey CurrentUser = new RegistryKey (
-                               RegistryHive.CurrentUser, "HKEY_CURRENT_USER");
+                               RegistryHive.CurrentUser);
+
+               [Obsolete ("Use PerformanceData instead")]
                public static readonly RegistryKey DynData = new RegistryKey (
-                               RegistryHive.DynData, "HKEY_DYN_DATA");
+                               RegistryHive.DynData);
                public static readonly RegistryKey LocalMachine = new RegistryKey (
-                               RegistryHive.LocalMachine, "HKEY_LOCAL_MACHINE");
+                               RegistryHive.LocalMachine);
                public static readonly RegistryKey PerformanceData = new RegistryKey (
-                               RegistryHive.PerformanceData, "HKEY_PERFORMANCE_DATA");
+                               RegistryHive.PerformanceData);
                public static readonly RegistryKey Users = new RegistryKey (
-                               RegistryHive.Users, "HKEY_USERS");
+                               RegistryHive.Users);
 
-#if NET_2_0
                static RegistryKey ToKey (string keyName, bool setting)
                {
                        if (keyName == null)
@@ -117,6 +113,18 @@ namespace Microsoft.Win32
 
                        key.SetValue (valueName, value);
                }
+
+               public static void SetValue (string keyName, string valueName, object value, RegistryValueKind valueKind)
+               {
+                       RegistryKey key = ToKey (keyName, true);
+                       if (valueName.Length > 255)
+                               throw new ArgumentException ("valueName is larger than 255 characters", "valueName");
+
+                       if (key == null)
+                               throw new ArgumentException ("cant locate that keyName", "keyName");
+
+                       key.SetValue (valueName, value, valueKind);
+               }
                
                public static object GetValue (string keyName, string valueName, object defaultValue)
                {
@@ -126,6 +134,8 @@ namespace Microsoft.Win32
                        
                        return key.GetValue (valueName, defaultValue);
                }
-#endif
        }
 }
+
+#endif // NET_2_1
+