System/PCL: Implement HttpWebRequest.SupportsCookieContainer, WebRequest.CreateHttp...
[mono.git] / mcs / class / System / System.Configuration / SettingsPropertyValue.cs
index 0efa28835450c4de6e7278d4fdc0e7dbd78d50f5..9bf62c00c62a743e986ca0439c5bd075f5f7678f 100644 (file)
@@ -26,7 +26,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
 using System;
 using System.Globalization;
 using System.IO;
@@ -114,22 +113,30 @@ namespace System.Configuration
                                        switch (property.SerializeAs)
                                        {
                                        case SettingsSerializeAs.String:
-                                               serializedValue = TypeDescriptor.GetConverter (property.PropertyType).ConvertToString (propertyValue);
+                                               serializedValue = TypeDescriptor.GetConverter (property.PropertyType).ConvertToInvariantString (propertyValue);
                                                break;
 #if (XML_DEP)
                                        case SettingsSerializeAs.Xml:
-                                               XmlSerializer serializer = new XmlSerializer (propertyValue.GetType());
-                                               StringWriter w = new StringWriter();
-
-                                               serializer.Serialize (w, propertyValue);
-                                               serializedValue = w.ToString();
+                                               if (propertyValue != null) {
+                                                       XmlSerializer serializer = new XmlSerializer (propertyValue.GetType ());
+                                                       StringWriter w = new StringWriter(CultureInfo.InvariantCulture);
+       
+                                                       serializer.Serialize (w, propertyValue);
+                                                       serializedValue = w.ToString();
+                                               }
+                                               else
+                                                       serializedValue = null;
                                                break;
 #endif
                                        case SettingsSerializeAs.Binary:
-                                               BinaryFormatter bf = new BinaryFormatter ();
-                                               MemoryStream ms = new MemoryStream ();
-                                               bf.Serialize (ms, propertyValue);
-                                               serializedValue = ms.ToArray();
+                                               if (propertyValue != null) {
+                                                       BinaryFormatter bf = new BinaryFormatter ();
+                                                       MemoryStream ms = new MemoryStream ();
+                                                       bf.Serialize (ms, propertyValue);
+                                                       serializedValue = ms.ToArray();
+                                               }
+                                               else
+                                                       serializedValue = null;
                                                break;
                                        default:
                                                serializedValue = null;
@@ -152,10 +159,19 @@ namespace System.Configuration
                        }
                }
 
+               internal object Reset ()
+               {
+                       propertyValue = GetDeserializedDefaultValue ();
+                       dirty = true;
+                       defaulted = true;
+                       needPropertyValue = true;
+                       return propertyValue;
+               }
+
                private object GetDeserializedDefaultValue ()
                {
                        if (property.DefaultValue == null)
-                               if (property.PropertyType.IsValueType)
+                               if (property.PropertyType != null && property.PropertyType.IsValueType)
                                        return Activator.CreateInstance (property.PropertyType);
                                else
                                        return null;
@@ -171,7 +187,7 @@ namespace System.Configuration
 
                        if (!property.PropertyType.IsAssignableFrom (property.DefaultValue.GetType ())) {
                                TypeConverter converter = TypeDescriptor.GetConverter (property.PropertyType);
-                               return converter.ConvertFrom (property.DefaultValue);
+                               return converter.ConvertFrom (null, CultureInfo.InvariantCulture, property.DefaultValue);
                        }
                        return property.DefaultValue;
                }
@@ -186,8 +202,8 @@ namespace System.Configuration
                        try {
                                switch (property.SerializeAs) {
                                        case SettingsSerializeAs.String:
-                                               if (serializedValue is string && ((string) serializedValue).Length > 0)
-                                                       deserializedObject = TypeDescriptor.GetConverter (property.PropertyType).ConvertFromString ((string) serializedValue);
+                                               if (serializedValue is string)
+                                                       deserializedObject = TypeDescriptor.GetConverter (property.PropertyType).ConvertFromInvariantString ((string) serializedValue);
                                                break;
 #if (XML_DEP)
                                        case SettingsSerializeAs.Xml:
@@ -227,4 +243,3 @@ namespace System.Configuration
 
 }
 
-#endif