2006-06-29 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Thu, 29 Jun 2006 05:06:20 +0000 (05:06 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Thu, 29 Jun 2006 05:06:20 +0000 (05:06 -0000)
* ApplicationSettingsBase.cs : When we use default value, convert it
  to proper type. Fixed bug #78654. Patch by Gareth Pearce.

* ApplicationSettingsBaseTest.cs : added test for bug #78654.

svn path=/trunk/mcs/; revision=62136

mcs/class/System/System.Configuration/ApplicationSettingsBase.cs
mcs/class/System/System.Configuration/ChangeLog
mcs/class/System/Test/System.Configuration/ApplicationSettingsBaseTest.cs
mcs/class/System/Test/System.Configuration/ChangeLog

index 2b5487be96ca32bedc4774c020ad9afc6c075d4f..b554e9903f4b1cea3bb25e78ef2dc1882ff0df41 100644 (file)
@@ -263,6 +263,9 @@ namespace System.Configuration {
                                                                }
                                                                else if (a is DefaultSettingValueAttribute) {
                                                                        defaultValue = ((DefaultSettingValueAttribute)a).Value; /* XXX this is a string.. do we convert? */
+                                                                       if (prop.PropertyType != typeof(string)) {
+                                                                               defaultValue = TypeDescriptor.GetConverter(prop.PropertyType).ConvertFromString((string)defaultValue);
+                                                                       }
                                                                }
                                                                else if (a is SettingsSerializeAsAttribute) {
                                                                        serializeAs = ((SettingsSerializeAsAttribute)a).SerializeAs;
index 578177bbb24bcb6c570b899613988fece7126cf9..bb42581969eefd91bd7188c6d5f9f4b4fb81ff8a 100644 (file)
@@ -1,3 +1,8 @@
+2006-06-29  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * ApplicationSettingsBase.cs : When we use default value, convert it
+         to proper type. Fixed bug #78654. Patch by Gareth Pearce.
+
 2006-05-30  Gert Driesen  <drieseng@users.sourceforge.net>
 
        * ConfigurationException.cs: BareMessage, Filename and Line properties
index 35388287108c647203825d0bc06591ffa205277b..3d61ca7d0ede5b4076f95c83818bfb1c01aa94da 100644 (file)
@@ -311,6 +311,21 @@ namespace MonoTests.System.Configuration {
                class Bug78430 : SettingsBase
                {
                }
+
+               [Test] // bug #78654
+               public void DefaultSettingValueAs ()
+               {
+                       Assert.AreEqual (1, new Bug78654 ().IntSetting);
+               }
+
+               class Bug78654 : ApplicationSettingsBase
+               {
+                       [UserScopedSettingAttribute ()]
+                       [DefaultSettingValueAttribute ("1")]
+                       public int IntSetting {
+                               get { return ((int)(this ["IntSetting"])); }
+                       }
+               }
        }
 
 }
index 947b84bc18725431d226f07f75624c2a82a59a94..ae09956394f1809ca21ce2f9c4a484f591942652 100644 (file)
@@ -1,3 +1,7 @@
+2006-06-29  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * ApplicationSettingsBaseTest.cs : added test for bug #78654.
+
 2006-05-17  Atsushi Enomoto  <atsushi@ximian.com>
 
        * LocalFileSettingsProviderTest.cs : commented some lines in