Author: iainmc
Date: 2005-07-08 09:22:05 -0400 (Fri, 08 Jul 2005)
New Revision: 47097

Modified:
   trunk/mcs/class/PresentationFramework/ChangeLog
   
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
   
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
   
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
Log:
2005-07-08  Iain McCoy  <[EMAIL PROTECTED]>

        * Mono.Windows.Serialization/XamlParser.cs,
          Mono.Windows.Serialization/XamlWriter.cs,
          Mono.Windows.Serialization/CodeWriter.cs: removed TypeConverter
          stuff from everything except CodeWriter. By using TypeDescriptor,
          the generator doesn't need to be told about the converter and since
          the framework will find it we don't have to search for it.



Modified: trunk/mcs/class/PresentationFramework/ChangeLog
===================================================================
--- trunk/mcs/class/PresentationFramework/ChangeLog     2005-07-08 12:59:09 UTC 
(rev 47096)
+++ trunk/mcs/class/PresentationFramework/ChangeLog     2005-07-08 13:22:05 UTC 
(rev 47097)
@@ -2,6 +2,15 @@
 
        * Mono.Windows.Serialization/XamlParser.cs,
          Mono.Windows.Serialization/XamlWriter.cs,
+         Mono.Windows.Serialization/CodeWriter.cs: removed TypeConverter
+         stuff from everything except CodeWriter. By using TypeDescriptor,
+         the generator doesn't need to be told about the converter and since
+         the framework will find it we don't have to search for it.
+
+2005-07-08  Iain McCoy  <[EMAIL PROTECTED]>
+
+       * Mono.Windows.Serialization/XamlParser.cs,
+         Mono.Windows.Serialization/XamlWriter.cs,
          Mono.Windows.Serialization/CodeWriter.cs: support for x:Name
          attributes and for considering Name properties to have the same
          affect.

Modified: 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
===================================================================
--- 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs  
    2005-07-08 12:59:09 UTC (rev 47096)
+++ 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs  
    2005-07-08 13:22:05 UTC (rev 47097)
@@ -222,20 +222,29 @@
                                        expr);
                        constructor.Statements.Add(assignment);
                }
+
+               private CodeExpression fetchConverter(Type propertyType)
+               {
+                       return new CodeMethodInvokeExpression(
+                                       new CodeMethodReferenceExpression(
+                                                       new 
CodeTypeReferenceExpression(typeof(System.ComponentModel.TypeDescriptor)),
+                                                       "GetConverter"),
+                                       new CodeTypeOfExpression(propertyType));
+               }
                // top of stack is reference to a property
-               public void CreatePropertyText(string text, Type propertyType, 
Type converterType)
+               public void CreatePropertyText(string text, Type propertyType)
                {
-                       CreateDependencyPropertyText(text, propertyType, 
converterType);
+                       CreateDependencyPropertyText(text, propertyType);
                }
                // top of stack is reference to an attached property
-               public void CreateDependencyPropertyText(string text, Type 
propertyType, Type converterType)
+               public void CreateDependencyPropertyText(string text, Type 
propertyType)
                {
                        CodeExpression expr = new CodePrimitiveExpression(text);
-                       if (converterType != null) {
+                       if (propertyType != typeof(string)) {
                                expr = new CodeCastExpression(
                                                new 
CodeTypeReference(propertyType),
                                                new CodeMethodInvokeExpression(
-                                                               new 
CodeObjectCreateExpression(converterType),
+                                                               
fetchConverter(propertyType),
                                                                
"ConvertFromString",
                                                                expr));
                        }

Modified: 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
===================================================================
--- 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs  
    2005-07-08 12:59:09 UTC (rev 47096)
+++ 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs  
    2005-07-08 13:22:05 UTC (rev 47097)
@@ -164,39 +164,13 @@
                                writer.CreateElementText(reader.Value);
                        } else if (currentState.type == 
CurrentType.DependencyProperty) {
                                DependencyProperty dp = 
(DependencyProperty)currentState.obj;
-                               
writer.CreateDependencyPropertyText(reader.Value, dp.PropertyType, 
-                                               
getTypeConverter(dp.PropertyType));
+                               
writer.CreateDependencyPropertyText(reader.Value, dp.PropertyType);
                        } else {
                                PropertyInfo prop = 
(PropertyInfo)currentState.obj;
-                               writer.CreatePropertyText(reader.Value, 
prop.PropertyType,
-                                               
getTypeConverter(prop.PropertyType));
+                               writer.CreatePropertyText(reader.Value, 
prop.PropertyType);
                        }
                }
                
-               Type getTypeConverter(Type fromType)
-               {
-                       // TODO: this business setting assembly is frankly
-                       // grotesque. It should just be something along the
-                       // lines of Assembly.Load("System.dll")
-                       Assembly assembly = null;
-                       foreach (Assembly a in 
AppDomain.CurrentDomain.GetAssemblies()) {
-                               if (a.CodeBase.EndsWith("System.dll")) {
-                                       assembly = a;
-                                       break;
-                               }
-                       }
-
-                       
-                       if (fromType.Namespace == "System" && 
-                                       fromType.Name == "String")
-                               return null;
-                       string converterName = "System.ComponentModel." + 
fromType.Name + "Converter,System.dll";
-                       Type converter = assembly.GetType(converterName);
-                       return converter;
-                       // TODO: check if converter == null and do something 
cool
-               }
-
-               
                void parseNormalPropertyElement(string propertyName)
                {
                        // preconditions: currentState.Type == Object
@@ -316,7 +290,7 @@
                        if (prop.PropertyType.IsSubclassOf(typeof(Delegate)))
                                writer.CreatePropertyDelegate(reader.Value, 
prop.PropertyType);
                        else
-                               writer.CreatePropertyText(reader.Value, 
prop.PropertyType, getTypeConverter(prop.PropertyType));
+                               writer.CreatePropertyText(reader.Value, 
prop.PropertyType);
                        
                        writer.EndProperty();
                }
@@ -373,8 +347,7 @@
                        DependencyProperty dp = 
getDependencyProperty(typeAttachedTo, propertyName);
                        
                        writer.CreateDependencyProperty(typeAttachedTo, 
propertyName, dp.PropertyType);
-                       writer.CreateDependencyPropertyText(reader.Value, 
dp.PropertyType, 
-                                       getTypeConverter(dp.PropertyType));
+                       writer.CreateDependencyPropertyText(reader.Value, 
dp.PropertyType);
                        writer.EndDependencyProperty();
                }
 

Modified: 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
===================================================================
--- 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs  
    2005-07-08 12:59:09 UTC (rev 47096)
+++ 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs  
    2005-07-08 13:22:05 UTC (rev 47097)
@@ -38,7 +38,7 @@
                void EndObject();
 
                void CreateProperty(PropertyInfo property);
-               void CreatePropertyText(string text, Type propertyType, Type 
converterType);
+               void CreatePropertyText(string text, Type propertyType);
                void CreatePropertyDelegate(string functionName, Type 
propertyType);
                void EndProperty();
        
@@ -48,7 +48,7 @@
                void EndEvent();
 
                void CreateDependencyProperty(Type attachedTo, string 
propertyName, Type propertyType);
-               void CreateDependencyPropertyText(string text, Type 
propertyType, Type converterType);
+               void CreateDependencyPropertyText(string text, Type 
propertyType);
                void EndDependencyProperty();
 
                void CreateCode(string code);

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

Reply via email to