Example #1
0
        internal static void MigrateUserSettings(ApplicationSettingsBase settings)
        {
            if (settings is IMigrateSettings)
            {
                IMigrateSettings customMigrator = (IMigrateSettings)settings;
                foreach (SettingsProperty property in settings.Properties)
                {
                    if (!SettingsPropertyExtensions.IsUserScoped(property))
                    {
                        continue;
                    }

                    object previousValue = settings.GetPreviousVersion(property.Name);

                    //need to do this to force the values to load before accessing the PropertyValues in order to migrate,
                    //otherwise the SettingsPropertyValue will always be null.
                    var iForceSettingsPropertyValuesToLoad = settings[property.Name];
                    var currentValue = settings.PropertyValues[property.Name];
                    MigrateProperty(customMigrator, MigrationScope.User, currentValue, previousValue);
                }
            }
            else
            {
                settings.Upgrade();
            }

            //Don't need to reload because the user settings will be current.
            SaveIfDirty(settings);
        }
 public static SettingScope GetScope(SettingsProperty property)
 {
     return(SettingsPropertyExtensions.IsUserScoped(property) ? SettingScope.User : SettingScope.Application);
 }
 private static bool IsUserScoped(SettingsProperty property)
 {
     return(SettingsPropertyExtensions.IsUserScoped(property));
 }