From:� Elan Feingold <efeingold@mn.rr.com>
authorMiguel de Icaza <miguel@gnome.org>
Mon, 24 Mar 2003 04:14:04 +0000 (04:14 -0000)
committerMiguel de Icaza <miguel@gnome.org>
Mon, 24 Mar 2003 04:14:04 +0000 (04:14 -0000)
Patch to support property-deserialization.

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

mcs/class/System.XML/System.Xml.Serialization/ChangeLog
mcs/class/System.XML/System.Xml.Serialization/XmlSerializer.cs

index 02916275a3493ec5ed21f082923c4e7ff680a13d..9450d1a60660193de120c36bbef126d9744ed56e 100755 (executable)
@@ -1,3 +1,8 @@
+2003-03-17  Miguel de Icaza  <miguel@ximian.com>
+
+       * XmlSerializer.cs: Do not use Bubblesort, use ArrayList.Sort.
+       Kill Bublesort.
+
 2003-03-22  Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
 
        * XmlSerializer.cs : patch by Sean Cier. Serialize() other than 
@@ -8,6 +13,7 @@
        * XmlSerializer.cs : Serialize() don't write xmldecl when WriteState is
          not WriteState.Start, and never call WriteEndDocument().
 
+>>>>>>> 1.26
 2003-03-12  Elan Feingold <efeingold@mn.rr.com>
 
        * XmlCustomFormatter.cs: Correct signature, Implement
index 561bb7fd76dd6b5c21ec513da2edfc3b7aff49d8..61d29bef5ab4aad1677362b5f9efba009adcbe45 100644 (file)
@@ -219,13 +219,33 @@ namespace System.Xml.Serialization {
                                                                         ref Object theObject,
                                                                         String         fieldName)
                {
-                       // Get the type
+                       //Console.WriteLine("DeserializeField({0})", fieldName);
+
+                       Type             fieldType = null;
+                       BindingFlags bindingFlags = 0;
+
+                       // Get the type, first try a field.
                        FieldInfo fieldInfo        = theObject.GetType().GetField(fieldName);
-                       Type      fieldType        = fieldInfo.FieldType;
+                       if (fieldInfo != null)
+                       {
+                               fieldType = fieldInfo.FieldType;
+                               bindingFlags = BindingFlags.SetField;
+                       }
+                       else
+                       {
+                               // Is it a property?
+                               PropertyInfo propInfo = theObject.GetType().GetProperty(fieldName);
+                               if (propInfo != null)
+                               {
+                                       fieldType = propInfo.PropertyType;
+                                       bindingFlags = BindingFlags.SetProperty;
+                               }
+                       }
+
                        Object    value            = null;
                        bool      isEmptyField = xmlReader.IsEmptyElement;
 
-                       //Console.WriteLine("DeserializeField({0} of type {1}", fieldName, fieldType);
+                       //Console.WriteLine("DeserializeField({0} of type {1})", fieldName, fieldType);
 
                        if (fieldType.IsArray && fieldType != typeof(System.Byte[]))
                        {
@@ -236,13 +256,10 @@ namespace System.Xml.Serialization {
                                DeserializeArray(xmlReader, list, fieldType.GetElementType());
                                value = list.ToArray(fieldType.GetElementType());
                        }
-                       else if (isEmptyField == true && fieldType.IsArray)
-                       {
-                               // Must be a byte array, just create an empty one.
-                               value = new byte[0];
-                       }
                        else if (isEmptyField == false && 
-                                        (IsInbuiltType(fieldType) || fieldType.IsEnum || fieldType.IsArray))
+                                        (IsInbuiltType(fieldType) || 
+                      fieldType.IsEnum || 
+                      fieldType.IsArray))
                        {
                                // Built in, set it.
                                while (xmlReader.Read())
@@ -272,6 +289,19 @@ namespace System.Xml.Serialization {
                                        }
                                }
                        }
+                       else if (isEmptyField == true)
+                       {
+                if  (fieldType.IsArray)
+                {
+                    // Must be a byte array, just create an empty one.
+                    value = new byte[0];
+                }
+                else if (fieldType == typeof(string))
+                {
+                    // Create a new empty string.
+                    value = "";
+                }
+                       }
                        else
                        {
                                //Console.WriteLine("Creating new {0}", fieldType);
@@ -287,7 +317,7 @@ namespace System.Xml.Serialization {
 
                        // Set the field value.
                        theObject.GetType().InvokeMember(fieldName,
-                                                                                        BindingFlags.SetField
+                                                                                        bindingFlags
                                                                                         null,
                                                                                         theObject, 
                                                                                         new Object[] { value },