Created
June 2, 2020 11:16
-
-
Save mrstebo/4d5d3e49b2bba4f682ce539aa9df65a9 to your computer and use it in GitHub Desktop.
c-net-registry-based-configuration-base-class-4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protected T GetValue<T>(string key, T defaultValue) | |
| { | |
| try | |
| { | |
| using (var rk = GetRegistryKey()) | |
| { | |
| using (var sk = rk.OpenSubKey(RootKey)) | |
| { | |
| object o = null; | |
| if (sk == null || (o = sk.GetValue(key, null)) == null) | |
| SetValue(key, (o = defaultValue)); | |
| return (T)o; | |
| } | |
| } | |
| } | |
| catch (Exception ex) | |
| { | |
| Trace.TraceError("Failed to get value for {0}: {1}", key, ex); | |
| throw; | |
| } | |
| } | |
| protected void SetValue<T>(string key, T value) | |
| { | |
| try | |
| { | |
| using (var rk = GetRegistryKey()) | |
| { | |
| using (var sk = rk.CreateSubKey(RootKey)) | |
| { | |
| sk.SetValue(key, value); | |
| } | |
| } | |
| } | |
| catch (Exception ex) | |
| { | |
| Trace.TraceError("Failed to set value for {0}: {1}", key, ex); | |
| throw; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment