public void GetUserScopedPropertyValues()
        {
            SettingsAttributeDictionary dict = new SettingsAttributeDictionary();
            UserScopedSettingAttribute  attr = new UserScopedSettingAttribute();

            dict.Add(attr.GetType(), attr);

            LocalFileSettingsProvider prov = new LocalFileSettingsProvider();
            SettingsContext           ctx  = new SettingsContext();
            SettingsProperty          p    = new SettingsProperty("property",
                                                                  typeof(int),
                                                                  prov,
                                                                  false,
                                                                  10,
                                                                  SettingsSerializeAs.Binary,
                                                                  dict,
                                                                  false,
                                                                  false);
            SettingsPropertyCollection      col = new SettingsPropertyCollection();
            SettingsPropertyValueCollection vals;

            col.Add(p);

            prov.Initialize(null, null);

            vals = prov.GetPropertyValues(ctx, col);
            Assert.IsNotNull(vals, "A1");
            Assert.AreEqual(1, vals.Count, "A2");
        }
Пример #2
0
 public static void EnsureProperties(FrameworkElement sender, Dictionary <FrameworkElement, DependencyProperty> savedElements)
 {
     foreach (FrameworkElement element in savedElements.Keys)
     {
         bool hasProperty =
             Properties.Settings.Default.Properties[sender.Name + "." + element.Name] != null;
         if (!hasProperty)
         {
             SettingsAttributeDictionary attributes = new SettingsAttributeDictionary();
             UserScopedSettingAttribute  attribute  = new UserScopedSettingAttribute();
             attributes.Add(attribute.GetType(), attribute);
             SettingsProperty property = new SettingsProperty(sender.Name + "." + element.Name,
                                                              savedElements[element].DefaultMetadata.DefaultValue.GetType(), Properties.Settings.Default.Providers["LocalFileSettingsProvider"], false, null, SettingsSerializeAs.String, attributes, true, true);
             Properties.Settings.Default.Properties.Add(property);
         }
     }
     Properties.Settings.Default.Reload();
 }