示例#1
0
        internal static void Save(ConfigurableObject configObject, SaveMode saveMode, ProviderPropertyDefinition[] appliedProperties, UserConfigurationDictionaryHelper.GetDictionaryUserConfigurationDelegate getDictionaryUserConfigurationDelegate)
        {
            Util.ThrowOnNullArgument(configObject, "configObject");
            Util.ThrowOnNullArgument(appliedProperties, "appliedProperties");
            bool flag = false;

            do
            {
                using (UserConfiguration userConfiguration = getDictionaryUserConfigurationDelegate(!flag))
                {
                    IDictionary dictionary = userConfiguration.GetDictionary();
                    foreach (ProviderPropertyDefinition providerPropertyDefinition in appliedProperties)
                    {
                        if (configObject.IsModified(providerPropertyDefinition))
                        {
                            object obj = configObject[providerPropertyDefinition];
                            if (obj == null)
                            {
                                dictionary.Remove(providerPropertyDefinition.Name);
                            }
                            else
                            {
                                dictionary[providerPropertyDefinition.Name] = StoreValueConverter.ConvertValueToStore(obj);
                            }
                        }
                    }
                    try
                    {
                        userConfiguration.Save(saveMode);
                        break;
                    }
                    catch (ObjectExistedException)
                    {
                        if (flag)
                        {
                            throw;
                        }
                        flag = true;
                    }
                }
            }while (flag);
        }