Author: krasnov
Date: 2006-11-05 06:53:45 -0500 (Sun, 05 Nov 2006)
New Revision: 67369

Modified:
   trunk/mcs/class/System/System.Configuration/ChangeLog
   trunk/mcs/class/System/System.Configuration/SettingsPropertyValue.cs
   trunk/mcs/class/System/Test/System.Configuration/ChangeLog
   trunk/mcs/class/System/Test/System.Configuration/SettingsPropertyValueTest.cs
Log:
* SettingsPropertyValue.cs: fixed PropertyValue property when it should be 
deserialized
* SettingsPropertyValueTest.cs: added tests of value deserealization


Modified: trunk/mcs/class/System/System.Configuration/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.Configuration/ChangeLog       2006-11-04 
22:32:08 UTC (rev 67368)
+++ trunk/mcs/class/System/System.Configuration/ChangeLog       2006-11-05 
11:53:45 UTC (rev 67369)
@@ -1,3 +1,8 @@
+2006-11-05  Vladimir Krasnov  <[EMAIL PROTECTED]>
+
+       * SettingsPropertyValue.cs: fixed PropertyValue property when it
+       should be deserialized.
+
 2006-10-13  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * ConfigurationSettings.cs :

Modified: trunk/mcs/class/System/System.Configuration/SettingsPropertyValue.cs
===================================================================
--- trunk/mcs/class/System/System.Configuration/SettingsPropertyValue.cs        
2006-11-04 22:32:08 UTC (rev 67368)
+++ trunk/mcs/class/System/System.Configuration/SettingsPropertyValue.cs        
2006-11-05 11:53:45 UTC (rev 67369)
@@ -29,8 +29,10 @@
 #if NET_2_0
 using System;
 using System.IO;
+using System.ComponentModel;
 using System.Runtime.Serialization.Formatters.Binary;
 #if (XML_DEP)
+using System.Xml;
 using System.Xml.Serialization;
 #endif
 
@@ -78,9 +80,12 @@
                public object PropertyValue {
                        get {
                                if (needPropertyValue) {
+                                       propertyValue = GetDeserializedValue ();
+                                       if (propertyValue == null) {
+                                               propertyValue = 
property.DefaultValue;
+                                               defaulted = true;
+                                       }
                                        needPropertyValue = false;
-                                       propertyValue = property.DefaultValue;
-                                       defaulted = true;
                                }
 
 #if notyet
@@ -142,6 +147,7 @@
                        }
                        set {
                                serializedValue = value;
+                               needPropertyValue = true;
                        }
                }
 
@@ -151,13 +157,48 @@
                        }
                }
 
+               private object GetDeserializedValue ()
+               {
+                       if (serializedValue == null)
+                               return null;
+
+                       object deserializedObject = null;
+
+                       try {
+                               switch (property.SerializeAs) {
+                                       case SettingsSerializeAs.String:
+                                               if (((string) 
serializedValue).Length > 0)
+                                                       deserializedObject = 
TypeDescriptor.GetConverter (property.PropertyType).ConvertFromString ((string) 
serializedValue);
+                                               break;
+#if (XML_DEP)
+                                       case SettingsSerializeAs.Xml:
+                                               XmlSerializer serializer = new 
XmlSerializer (property.PropertyType);
+                                               StringReader str = new 
StringReader ((string) serializedValue);
+                                               deserializedObject = 
serializer.Deserialize (XmlReader.Create (str));
+                                               break;
+#endif
+                                       case SettingsSerializeAs.Binary:
+                                               BinaryFormatter bf = new 
BinaryFormatter ();
+                                               MemoryStream ms = new 
MemoryStream ((byte []) serializedValue);
+                                               deserializedObject = 
bf.Deserialize (ms);
+                                               break;
+                               }
+                       }
+                       catch (Exception e) {
+                               if (property.ThrowOnErrorDeserializing)
+                                       throw e;
+                       }
+
+                       return deserializedObject;
+               }
+
                SettingsProperty property;
                object propertyValue;
                object serializedValue;
                bool needSerializedValue;
                bool needPropertyValue;
                bool dirty;
-               bool defaulted;
+               bool defaulted = false;
                bool deserialized;
        }
 

Modified: trunk/mcs/class/System/Test/System.Configuration/ChangeLog
===================================================================
--- trunk/mcs/class/System/Test/System.Configuration/ChangeLog  2006-11-04 
22:32:08 UTC (rev 67368)
+++ trunk/mcs/class/System/Test/System.Configuration/ChangeLog  2006-11-05 
11:53:45 UTC (rev 67369)
@@ -1,3 +1,7 @@
+2006-11-05  Vladimir Krasnov  <[EMAIL PROTECTED]>
+
+       * SettingsPropertyValueTest.cs: added tests of value deserealization
+
 2006-06-29  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * ApplicationSettingsBaseTest.cs : added test for bug #78654.

Modified: 
trunk/mcs/class/System/Test/System.Configuration/SettingsPropertyValueTest.cs
===================================================================
--- 
trunk/mcs/class/System/Test/System.Configuration/SettingsPropertyValueTest.cs   
    2006-11-04 22:32:08 UTC (rev 67368)
+++ 
trunk/mcs/class/System/Test/System.Configuration/SettingsPropertyValueTest.cs   
    2006-11-05 11:53:45 UTC (rev 67369)
@@ -162,6 +162,48 @@
                }
 
                [Test]
+               public void String_Deserialize ()
+               {
+                       SettingsProperty p = new SettingsProperty ("property",
+                                                                  typeof (int),
+                                                                  null,
+                                                                  true,
+                                                                  10,
+                                                                  
SettingsSerializeAs.String,
+                                                                  null,
+                                                                  true,
+                                                                  false);
+
+                       SettingsPropertyValue v = new SettingsPropertyValue (p);
+                       v.SerializedValue = "123";
+
+                       Assert.AreEqual (123, v.PropertyValue, "A1");
+                       Assert.AreEqual (typeof(int), v.PropertyValue.GetType 
(), "A2");
+                       Assert.AreEqual (false, v.UsingDefaultValue, "A3");
+               }
+
+               [Test]
+               public void Xml_Deserialize ()
+               {
+                       SettingsProperty p = new SettingsProperty ("property",
+                                                                  typeof (int),
+                                                                  null,
+                                                                  true,
+                                                                  10,
+                                                                  
SettingsSerializeAs.Xml,
+                                                                  null,
+                                                                  true,
+                                                                  false);
+
+                       SettingsPropertyValue v = new SettingsPropertyValue (p);
+                       v.SerializedValue = "<?xml version=\"1.0\" 
encoding=\"utf-16\"?>\n<int>123</int>";
+
+                       Assert.AreEqual (123, v.PropertyValue, "A1");
+                       Assert.AreEqual (typeof(int), v.PropertyValue.GetType 
(), "A2");
+                       Assert.AreEqual (false, v.UsingDefaultValue, "A3");
+               }
+
+               [Test]
                public void String_Xml_Serialize ()
                {
                        SettingsProperty p = new SettingsProperty ("property",

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to