View | Details | Raw Unified | Return to bug 8592
Collapse All | Expand All

(-)mcs/class/System/System.Configuration/ApplicationSettingsBase.cs (-10 / +11 lines)
Lines 84-91 namespace System.Configuration { Link Here
84
#if (CONFIGURATION_DEP)
84
#if (CONFIGURATION_DEP)
85
			foreach (SettingsProvider provider in Providers) {
85
			foreach (SettingsProvider provider in Providers) {
86
				IApplicationSettingsProvider iasp = provider as IApplicationSettingsProvider;
86
				IApplicationSettingsProvider iasp = provider as IApplicationSettingsProvider;
87
				if (iasp != null)
87
				CacheValuesByProvider(provider);
88
					iasp.Reset (Context);
89
			}
88
			}
90
#endif
89
#endif
91
		}
90
		}
Lines 93-106 namespace System.Configuration { Link Here
93
		public void Reset()
92
		public void Reset()
94
		{
93
		{
95
#if (CONFIGURATION_DEP)
94
#if (CONFIGURATION_DEP)
96
			// Code bellow is identical to code in Reload().
97
			// foreach (SettingsProvider provider in Providers) {
98
			//         IApplicationSettingsProvider iasp = provider as IApplicationSettingsProvider;
99
			//         if (iasp != null)
100
			//		iasp.Reset (Context);
101
			// }
102
                                                
103
			Reload ();
95
			Reload ();
96
			foreach (SettingsPropertyValue pv in PropertyValues)
97
				pv.PropertyValue = pv.Reset();
104
#endif
98
#endif
105
		}
99
		}
106
100
Lines 190-196 namespace System.Configuration { Link Here
190
184
191
			if (col.Count > 0) {
185
			if (col.Count > 0) {
192
				SettingsPropertyValueCollection vals = provider.GetPropertyValues (Context, col);
186
				SettingsPropertyValueCollection vals = provider.GetPropertyValues (Context, col);
193
				PropertyValues.Add (vals);
187
				foreach (SettingsPropertyValue prop in vals) {
188
					if (PropertyValues[prop.Name] != null) {
189
						PropertyValues[prop.Name].PropertyValue = prop.PropertyValue;
190
					}
191
					else {
192
						PropertyValues.Add (prop);
193
					}
194
				}
194
			}
195
			}
195
196
196
			OnSettingsLoaded (this, new SettingsLoadedEventArgs (provider));
197
			OnSettingsLoaded (this, new SettingsLoadedEventArgs (provider));
(-)mcs/class/System/System.Configuration/CustomizableFileSettingsProvider.cs (-21 / +20 lines)
Lines 792-812 namespace System.Configuration Link Here
792
		{
792
		{
793
			CreateExeMap ();
793
			CreateExeMap ();
794
794
795
			if (values == null) {
795
			values = new SettingsPropertyValueCollection ();
796
				values = new SettingsPropertyValueCollection ();
796
			string groupName = context ["GroupName"] as string;
797
				string groupName = context ["GroupName"] as string;
797
			groupName = NormalizeInvalidXmlChars (groupName); // we likely saved the element removing the non valid xml chars.
798
				groupName = NormalizeInvalidXmlChars (groupName); // we likely saved the element removing the non valid xml chars.
798
			LoadProperties (exeMapCurrent, collection, ConfigurationUserLevel.None, "applicationSettings", false, groupName);
799
				LoadProperties (exeMapCurrent, collection, ConfigurationUserLevel.None, "applicationSettings", false, groupName);
799
			LoadProperties (exeMapCurrent, collection, ConfigurationUserLevel.None, "userSettings", false, groupName);
800
				LoadProperties (exeMapCurrent, collection, ConfigurationUserLevel.None, "userSettings", false, groupName);
800
801
801
			LoadProperties (exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoaming, "userSettings", true, groupName);
802
				LoadProperties (exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoaming, "userSettings", true, groupName);
802
			LoadProperties (exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoamingAndLocal, "userSettings", true, groupName);
803
				LoadProperties (exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoamingAndLocal, "userSettings", true, groupName);
803
804
804
			// create default values if not exist
805
				// create default values if not exist
805
			foreach (SettingsProperty p in collection)
806
				foreach (SettingsProperty p in collection)
806
				if (values [p.Name] == null)
807
					if (values [p.Name] == null)
807
					values.Add (new SettingsPropertyValue (p));
808
						values.Add (new SettingsPropertyValue (p));
809
			}
810
			return values;
808
			return values;
811
		}
809
		}
812
810
Lines 859-871 namespace System.Configuration Link Here
859
		public void Reset (SettingsContext context)
857
		public void Reset (SettingsContext context)
860
		{
858
		{
861
			SettingsPropertyCollection coll = new SettingsPropertyCollection ();
859
			SettingsPropertyCollection coll = new SettingsPropertyCollection ();
862
			GetPropertyValues (context, coll);
860
			// GetPropertyValues (context, coll);
863
			foreach (SettingsPropertyValue propertyValue in values) {
861
			if (values != null) {
864
				// Can't use propertyValue.Property.DefaultValue
862
				foreach (SettingsPropertyValue propertyValue in values) {
865
				// as it may cause InvalidCastException (see bug# 532180)
863
					// Can't use propertyValue.Property.DefaultValue
866
				propertyValue.PropertyValue = propertyValue.Reset ();
864
					// as it may cause InvalidCastException (see bug# 532180)
865
					values[propertyValue.Name].PropertyValue = propertyValue.Reset ();
866
				}
867
			}
867
			}
868
			SetPropertyValues (context, values);
869
		}
868
		}
870
869
871
		// FIXME: implement
870
		// FIXME: implement
(-)mcs/class/System/System.Configuration/SettingsPropertyValue.cs (-1 / +1 lines)
Lines 171-177 namespace System.Configuration Link Here
171
		private object GetDeserializedDefaultValue ()
171
		private object GetDeserializedDefaultValue ()
172
		{
172
		{
173
			if (property.DefaultValue == null)
173
			if (property.DefaultValue == null)
174
				if (property.PropertyType.IsValueType)
174
				if (property.PropertyType != null && property.PropertyType.IsValueType)
175
					return Activator.CreateInstance (property.PropertyType);
175
					return Activator.CreateInstance (property.PropertyType);
176
				else
176
				else
177
					return null;
177
					return null;
(-)mcs/class/System/Test/System.Configuration/ApplicationSettingsBaseTest.cs (+25 lines)
Lines 387-392 namespace MonoTests.System.Configuration { Link Here
387
                        settings.Reload();
387
                        settings.Reload();
388
                        Assert.AreEqual(10, settings.IntSetting, "A3");
388
                        Assert.AreEqual(10, settings.IntSetting, "A3");
389
                }                        
389
                }                        
390
		
391
		class Bug8592ConfHolder : ApplicationSettingsBase {
392
			[UserScopedSetting]
393
			public string TestKey1OnHolder { get { return (string)this["TestKey1OnHolder"] ?? ""; } set { this["TestKey1OnHolder"] = value; } }
394
		}
395
396
		[Test]
397
		public void TestBug8592BasicOperations() {
398
			var holder = new Bug8592ConfHolder();
399
			holder.Reset();
400
			holder.Save();
401
			Assert.AreEqual("", holder.TestKey1OnHolder);
402
			holder.TestKey1OnHolder = "candy";
403
			Assert.AreEqual("candy", holder.TestKey1OnHolder);
404
			holder.Reload();
405
			Assert.AreEqual("", holder.TestKey1OnHolder);
406
			holder.TestKey1OnHolder = "candy";
407
			Assert.AreEqual("candy", holder.TestKey1OnHolder);
408
			holder.Save();
409
			Assert.AreEqual("candy", holder.TestKey1OnHolder);
410
			holder.Reload();
411
			Assert.AreEqual("candy", holder.TestKey1OnHolder);
412
			holder.Reset();
413
			Assert.AreEqual("", holder.TestKey1OnHolder);
414
		}
390
	}
415
	}
391
}
416
}
392
417

Return to bug 8592