public static OpenRegistryKey ( ) : |
||
리턴 |
public static void WriteCurrentVersionToRegistry() { using (var registryKey = RegistryAccess.OpenRegistryKey()) { var publishedVersion = GetPublishedVersion().ToString(); registryKey.SetValue("LastLaunchedVersion", publishedVersion); } }
public static void SaveSettings(Settings settings) { using (var s = new MemoryStream()) { using (var registryKey = RegistryAccess.OpenRegistryKey()) { var serializer = new DataContractJsonSerializer(settings.GetType()); serializer.WriteObject(s, settings); var value = Encoding.UTF8.GetString(s.ToArray()); registryKey.SetValue("Settings", value); } } }
public static bool CurrentVersionIsDifferentFromLastRunVersion() { using (var registryKey = RegistryAccess.OpenRegistryKey()) { var value = registryKey.GetValue("LastLaunchedVersion", "1.0.0.0") as string; var publishedVersion = GetPublishedVersion().ToString(); if (value == publishedVersion) { return(true); } else { return(false); } } }
public static T LoadSettings <T>() where T : Settings, new() { try { using (var registryKey = RegistryAccess.OpenRegistryKey()) { var value = registryKey.GetValue("Settings") as string; using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(value))) { var serializer = new DataContractJsonSerializer(typeof(T)); return(serializer.ReadObject(memoryStream) as T); } } } catch { return(new T()); } }