public static void SaveMruList(MostRecentlyUsedContainer container) { Guard.NotNull(container, nameof(container)); IgnoreErrors(() => { using RegistryKey appSettingsKey = Registry.CurrentUser.CreateSubKey(RegistryPath); ExportContainerToKey(container, appSettingsKey); }); }
private static void ImportContainerFromKey(RegistryKey appSettingsKey, MostRecentlyUsedContainer container) { if (appSettingsKey.GetValue(MruRegistryPath) is string valueList) { string[] values = valueList.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); container.Import(values.Take(MruMaxLength)); } }
public static MostRecentlyUsedContainer GetMruList() { return(IgnoreErrors(() => { using RegistryKey? appSettingsKey = Registry.CurrentUser.OpenSubKey(RegistryPath); var container = new MostRecentlyUsedContainer(); if (appSettingsKey != null) { ImportContainerFromKey(appSettingsKey, container); } return container; }, new MostRecentlyUsedContainer())); }
private static void ExportContainerToKey(MostRecentlyUsedContainer container, RegistryKey appSettingsKey) { string valueList = string.Join(";", container.Items.Take(MruMaxLength)); appSettingsKey.SetValue(MruRegistryPath, valueList); }