Ignore:
Timestamp:
2/8/2010 8:25:51 AM (2 years ago)
Author:
lowjoel
Message:

Allow all IDisposable patterns to be reentrant. Addresses #275: Code Review

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/CodeReview/Eraser/Settings.cs

    r1770 r1772  
    4949            public RegistrySettings(Guid pluginId, RegistryKey key) 
    5050            { 
    51                 this.pluginID = pluginId; 
    52                 this.key = key; 
     51                this.PluginID = pluginId; 
     52                this.Key = key; 
    5353            } 
    5454 
     
    6868            private void Dispose(bool disposing) 
    6969            { 
     70                if (Key == null) 
     71                    return; 
     72 
    7073                if (disposing) 
    71                     key.Close(); 
     74                    Key.Close(); 
     75                Key = null; 
    7276            } 
    7377 
     
    7983                { 
    8084                    //Get the raw registry value 
    81                     object rawResult = key.GetValue(setting, null); 
     85                    object rawResult = Key.GetValue(setting, null); 
    8286 
    8387                    //Check if it is a serialised object 
     
    9296                            catch (SerializationException) 
    9397                            { 
    94                                 key.DeleteValue(setting); 
     98                                Key.DeleteValue(setting); 
    9599                                MessageBox.Show(S._("Could not load the setting {0}\\{1} for " + 
    96                                         "plugin {2}. The setting has been lost.", key, setting, 
    97                                         pluginID.ToString()), 
     100                                        "plugin {2}. The setting has been lost.", Key, setting, 
     101                                        PluginID.ToString()), 
    98102                                    S._("Eraser"), MessageBoxButtons.OK, MessageBoxIcon.Error, 
    99103                                    MessageBoxDefaultButton.Button1, 
     
    113117                    if (value == null) 
    114118                    { 
    115                         key.DeleteValue(setting); 
     119                        Key.DeleteValue(setting); 
    116120                    } 
    117121                    else 
    118122                    { 
    119123                        if (value is bool) 
    120                             key.SetValue(setting, value, RegistryValueKind.DWord); 
     124                            Key.SetValue(setting, value, RegistryValueKind.DWord); 
    121125                        else if ((value is int) || (value is uint)) 
    122                             key.SetValue(setting, value, RegistryValueKind.DWord); 
     126                            Key.SetValue(setting, value, RegistryValueKind.DWord); 
    123127                        else if ((value is long) || (value is ulong)) 
    124                             key.SetValue(setting, value, RegistryValueKind.QWord); 
     128                            Key.SetValue(setting, value, RegistryValueKind.QWord); 
    125129                        else if (value is string) 
    126                             key.SetValue(setting, value, RegistryValueKind.String); 
     130                            Key.SetValue(setting, value, RegistryValueKind.String); 
    127131                        else 
    128132                            using (MemoryStream stream = new MemoryStream()) 
    129133                            { 
    130134                                new BinaryFormatter().Serialize(stream, value); 
    131                                 key.SetValue(setting, stream.ToArray(), RegistryValueKind.Binary); 
     135                                Key.SetValue(setting, stream.ToArray(), RegistryValueKind.Binary); 
    132136                            } 
    133137                    } 
     
    138142            /// The GUID of the plugin whose settings this object is storing. 
    139143            /// </summary> 
    140             private Guid pluginID; 
     144            private Guid PluginID; 
    141145 
    142146            /// <summary> 
    143147            /// The registry key where the data is stored. 
    144148            /// </summary> 
    145             private RegistryKey key; 
     149            private RegistryKey Key; 
    146150        } 
    147151 
Note: See TracChangeset for help on using the changeset viewer.