Author: mhabersack
Date: 2007-05-25 13:06:44 -0400 (Fri, 25 May 2007)
New Revision: 77952

Modified:
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSourceView.cs
Log:
2007-05-25  Marek Habersack  <[EMAIL PROTECTED]>

        * ObjectDataSourceView.cs: CreateDataObject must pay attention to
        TypeConverter attributes on the property being converted.


Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog      
2007-05-25 17:06:17 UTC (rev 77951)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog      
2007-05-25 17:06:44 UTC (rev 77952)
@@ -1,3 +1,8 @@
+2007-05-25  Marek Habersack  <[EMAIL PROTECTED]>
+
+       * ObjectDataSourceView.cs: CreateDataObject must pay attention to
+       TypeConverter attributes on the property being converted.
+
 2007-05-24 Igor Zelmanovich <[EMAIL PROTECTED]>
 
        * Menu.cs: fixed: alt attribute is rendered as well.

Modified: 
trunk/mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSourceView.cs
===================================================================
--- 
trunk/mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSourceView.cs    
    2007-05-25 17:06:17 UTC (rev 77951)
+++ 
trunk/mcs/class/System.Web/System.Web.UI.WebControls/ObjectDataSourceView.cs    
    2007-05-25 17:06:44 UTC (rev 77952)
@@ -933,7 +933,15 @@
                        foreach (DictionaryEntry de in values) {
                                PropertyInfo p = DataObjectType.GetProperty 
((string)de.Key);
                                if (p == null) throw new 
InvalidOperationException ("Property " + de.Key + " not found in type '" 
+DataObjectType + "'.");
-                               p.SetValue (ob, ConvertParameter 
(p.PropertyType, de.Value), null);
+                               object[] attributes = p.GetCustomAttributes 
(typeof (System.ComponentModel.TypeConverterAttribute),
+                                                                            
true);
+                               Type propertyType = p.PropertyType;
+                               object value = de.Value;
+                               object converted = 
ConvertParameterWithTypeConverter (attributes, propertyType, value);
+                               if (converted == null)
+                                       converted = ConvertParameter 
(propertyType, value);
+                                                  
+                               p.SetValue (ob, converted, null);
                        }
                        return ob;
                }
@@ -1033,11 +1041,13 @@
 
                        outParamInfos = null;
                        object[] values = new object [methodParams.Length];
+                       object converted;
+                       
                        foreach (ParameterInfo mp in methodParams) {
                        
                                // Parameter names must match
                                if (!viewParams.Contains (mp.Name)) return null;
-                                       
+                               
                                values [mp.Position] = ConvertParameter 
(mp.ParameterType, viewParams [mp.Name]);
                                if (mp.ParameterType.IsByRef) {
                                        if (outParamInfos == null) 
outParamInfos = new ArrayList ();
@@ -1046,6 +1056,33 @@
                        }
                        return values;
                }
+
+               object ConvertParameterWithTypeConverter (object[] attributes, 
Type targetType, object value)
+               {
+                       if (attributes == null || attributes.Length == 0 || 
value == null)
+                               return null;
+                       TypeConverterAttribute tca;
+                       Type converterType;
+                       TypeConverter converter;
+                       
+                       foreach (object a in attributes) {
+                               tca = a as TypeConverterAttribute;
+                               if (tca == null)
+                                       continue;
+                               converterType = Type.GetType 
(tca.ConverterTypeName, false);
+                               if (converterType == null)
+                                       continue;
+                               converter = Activator.CreateInstance 
(converterType, new object[] {targetType}) as TypeConverter;
+                               if (converter == null)
+                                       continue;
+                               if (converter.CanConvertFrom (value.GetType ()))
+                                       return converter.ConvertFrom (value);
+                               else if (converter.CanConvertFrom (typeof 
(string)))
+                                       return converter.ConvertFrom 
(value.ToString ());
+                       }
+                       
+                       return null;
+               }
                
                object ConvertParameter (Type targetType, object value)
                {

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

Reply via email to