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
| public string TestSetting1 | |
| { | |
| get | |
| { | |
| return GetValue(ParsePropertyMethodName(MethodBase.GetCurrentMethod().Name), string.Empty); | |
| } | |
| set | |
| { | |
| SetValue(ParsePropertyMethodName(MethodBase.GetCurrentMethod().Name), value); | |
| } |
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
| public sealed class TestConfig : RegistryConfig | |
| { | |
| public TestConfig() | |
| : base(RegistryHive.CurrentUser, @"SOFTWARE\Test") | |
| { | |
| } | |
| } |
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 static string ParsePropertyMethodName(string methodName) | |
| { | |
| if (methodName.StartsWith("get_") || methodName.StartsWith("set_")) | |
| methodName = methodName.Substring(4); | |
| return methodName; | |
| } |
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
| public void Initialize() | |
| { | |
| foreach (var propInfo in GetProperties()) | |
| { | |
| try | |
| { | |
| if (propInfo != null) | |
| { | |
| var o = propInfo.GetValue(this, null); | |
| } |
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 virtual IEnumerable<PropertyInfo> GetProperties() | |
| { | |
| return GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase | BindingFlags.GetProperty); | |
| } |
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
| using Microsoft.Win32; | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Diagnostics; | |
| using System.Reflection; | |
| namespace ns_stebo | |
| { | |
| public abstract class RegistryConfig | |
| { |
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
| public bool Exists(string key) | |
| { | |
| return GetValue<object>(key, null) != null; | |
| } |
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) |
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 RegistryKey GetRegistryKey() | |
| { | |
| switch (Hive) | |
| { | |
| case RegistryHive.ClassesRoot: | |
| return Registry.ClassesRoot; | |
| case RegistryHive.CurrentConfig: | |
| return Registry.CurrentConfig; |
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
| namespace ns_stebo | |
| { | |
| public abstract class RegistryConfig | |
| { | |
| public RegistryHive Hive | |
| { | |
| get; | |
| private set; | |
| } |