Author: iainmc
Date: 2005-07-05 09:23:57 -0400 (Tue, 05 Jul 2005)
New Revision: 46945

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/tools/xamlc/ChangeLog
   trunk/mcs/tools/xamlc/README
   trunk/mcs/tools/xamlc/demo/test.xaml
Log:
2005-07-05  Iain McCoy  <[EMAIL PROTECTED]>

        * Mono.Windows.Serialization/XamlParser.cs,
          Mono.Windows.Serialization/XamlWriter.cs,
          Mono.Windows.Serialization/CodeWriter.cs: add support for attached
          properties as attributes, supplementing the existing support for
          attached properties as elements



Modified: trunk/mcs/class/PresentationFramework/ChangeLog
===================================================================
--- trunk/mcs/class/PresentationFramework/ChangeLog     2005-07-05 13:05:00 UTC 
(rev 46944)
+++ trunk/mcs/class/PresentationFramework/ChangeLog     2005-07-05 13:23:57 UTC 
(rev 46945)
@@ -2,6 +2,14 @@
 
        * Mono.Windows.Serialization/XamlParser.cs,
          Mono.Windows.Serialization/XamlWriter.cs,
+         Mono.Windows.Serialization/CodeWriter.cs: add support for attached
+         properties as attributes, supplementing the existing support for
+         attached properties as elements
+
+2005-07-05  Iain McCoy  <[EMAIL PROTECTED]>
+
+       * Mono.Windows.Serialization/XamlParser.cs,
+         Mono.Windows.Serialization/XamlWriter.cs,
          Mono.Windows.Serialization/CodeWriter.cs: add support for delegate
          properties and for events
        * Mono.Windows.Serialization/XamlParser.cs,

Modified: 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
===================================================================
--- 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs  
    2005-07-05 13:05:00 UTC (rev 46944)
+++ 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs  
    2005-07-05 13:23:57 UTC (rev 46945)
@@ -132,10 +132,8 @@
                public void CreateAttachedProperty(Type attachedTo, string 
propertyName, Type propertyType)
                {
                        string varName = "temp";
-                       if (tempIndex != 0) {
-                               varName += tempIndex;
-                               tempIndex += 1;
-                       }
+                       varName += tempIndex;
+                       tempIndex += 1;
                        CodeVariableDeclarationStatement decl = new 
CodeVariableDeclarationStatement(propertyType, varName);
                        constructor.Statements.Add(decl);
 

Modified: 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
===================================================================
--- 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs  
    2005-07-05 13:05:00 UTC (rev 46944)
+++ 
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs  
    2005-07-05 13:23:57 UTC (rev 46945)
@@ -223,28 +223,13 @@
                        }
                }
 
+
                void parseAttachedPropertyElement(string attachedTo, string 
propertyName)
                {
-                       Type typeAttachedTo = null;
-                       FieldInfo propField;
-                       DependencyProperty dp;
                        Type currentType = (Type)currentState.obj;
-                       if 
(!currentType.IsSubclassOf(typeof(System.Windows.DependencyObject)))
-                                       throw new Exception("Attached 
properties can only be set on "+
-                                                       "DependencyObjects (not 
" + currentType.Name + ")");
-                       foreach (ParserState state in oldStates) {
-                               if (state.type == CurrentType.Object &&
-                                               ((Type)state.obj).Name == 
attachedTo) {
-                                       typeAttachedTo = (Type)state.obj;
-                                       break;
-                               }
-                       }
-                       if (typeAttachedTo == null)
-                               throw new Exception("Nothing to attach to: " + 
attachedTo + "." + propertyName);
-                       propField = typeAttachedTo.GetField(propertyName + 
"Property");
-                       if (propField == null)
-                               throw new Exception("Property " + propertyName 
+ " does not exist on " + attachedTo);
-                       dp = (DependencyProperty)propField.GetValue(null);
+                       ensureDependencyObject(currentType);
+                       Type typeAttachedTo = findTypeToAttachTo(attachedTo, 
propertyName);
+                       DependencyProperty dp = 
getDependencyProperty(typeAttachedTo, propertyName);
                        
                        oldStates.Add(currentState);
                        currentState = new ParserState();
@@ -346,11 +331,50 @@
                        return true;
                }
 
+               void ensureDependencyObject(Type currentType)
+               {
+                       if 
(!currentType.IsSubclassOf(typeof(System.Windows.DependencyObject)))
+                                       throw new Exception("Attached 
properties can only be set on "+
+                                                       "DependencyObjects (not 
" + currentType.Name + ")");
+               }
+               Type findTypeToAttachTo(string attachedTo, string propertyName)
+               {
+                       Type typeAttachedTo = null;
+                       foreach (ParserState state in oldStates) {
+                               if (state.type == CurrentType.Object &&
+                                               ((Type)state.obj).Name == 
attachedTo) {
+                                       typeAttachedTo = (Type)state.obj;
+                                       break;
+                               }
+                       }
+                       if (typeAttachedTo == null)
+                               throw new Exception("Nothing to attach to: " + 
attachedTo + "." + propertyName);
+                       return typeAttachedTo;
+               }
 
+               DependencyProperty getDependencyProperty(Type typeAttachedTo, 
string propertyName)
+               {
+                       FieldInfo propField = 
typeAttachedTo.GetField(propertyName + "Property");
+                       if (propField == null)
+                               throw new Exception("Property " + propertyName 
+ " does not exist on " + typeAttachedTo.Name);
+                       return (DependencyProperty)propField.GetValue(null);
+               }
 
                void parseContextPropertyAttribute()
                {
-                       throw new 
NotImplementedException("parseContextPropertyAttribute");
+                       int index = reader.LocalName.LastIndexOf('.');
+                       string attachedTo = reader.LocalName.Substring(0, 
index);
+                       string propertyName = reader.LocalName.Substring(index 
+ 1);
+                       
+                       Type currentType = (Type)currentState.obj;
+                       ensureDependencyObject(currentType);
+                       Type typeAttachedTo = findTypeToAttachTo(attachedTo, 
propertyName);
+                       DependencyProperty dp = 
getDependencyProperty(typeAttachedTo, propertyName);
+                       
+                       writer.CreateAttachedProperty(typeAttachedTo, 
propertyName, dp.PropertyType);
+                       writer.CreateAttachedPropertyText(reader.Value, 
dp.PropertyType, 
+                                       getTypeConverter(dp.PropertyType));
+                       writer.EndAttachedProperty();
                }
 
                void parseEndElement()

Modified: trunk/mcs/tools/xamlc/ChangeLog
===================================================================
--- trunk/mcs/tools/xamlc/ChangeLog     2005-07-05 13:05:00 UTC (rev 46944)
+++ trunk/mcs/tools/xamlc/ChangeLog     2005-07-05 13:23:57 UTC (rev 46945)
@@ -1,5 +1,10 @@
 2005-07-05  Iain McCoy  <[EMAIL PROTECTED]>
 
+       * README: updated to reflect current output of demo
+       * demo/test.xaml: add attached property attribute demo
+
+2005-07-05  Iain McCoy  <[EMAIL PROTECTED]>
+
        * README: describe the demo as it currently is
        * demo/TestVocab/ConsoleWriter.cs: delegates demonstration
        * demo/TestVocab/ConsoleApp.cs: events demonstration

Modified: trunk/mcs/tools/xamlc/README
===================================================================
--- trunk/mcs/tools/xamlc/README        2005-07-05 13:05:00 UTC (rev 46944)
+++ trunk/mcs/tools/xamlc/README        2005-07-05 13:23:57 UTC (rev 46945)
@@ -14,13 +14,13 @@
 button.AddText("Click");
 
 Except of course it can handle trees of arbitrary depth, so descriptions of
-complicated GUIs are not a problem and much more readable than the code
-version.
+complicated GUIs are not a problem and potentially much more readable than 
+the code version.
 
 To use this thing:
-cd ../WindowsBase
+cd ../../class/WindowsBase
 make install
-cd class/PresentationFramework
+cd ../PresentationFramework
 make install
 cd ../../tools/xamlc
 make install
@@ -29,9 +29,14 @@
 directory; to run it, cd into that directory and do "make run". Stuff should 
 happen, along the lines of a program test.exe being generated and run to 
 produce this output:
+
 IT BEGINS!
 Hello World
+YYYI'm surrounded!ZZZ
 Goodbye.
 Goodbye.
 Goodbye.
+Bye
+Bye
+
 You should be able to see how that's made from the included test.xaml file

Modified: trunk/mcs/tools/xamlc/demo/test.xaml
===================================================================
--- trunk/mcs/tools/xamlc/demo/test.xaml        2005-07-05 13:05:00 UTC (rev 
46944)
+++ trunk/mcs/tools/xamlc/demo/test.xaml        2005-07-05 13:23:57 UTC (rev 
46945)
@@ -11,6 +11,7 @@
                <ConsoleApp.Repetitions>3</ConsoleApp.Repetitions>
                <ConsoleWriter.Text>Goodbye.</ConsoleWriter.Text>
        </ConsoleWriter>
+       <ConsoleWriter ConsoleApp.Repetitions="2">Bye</ConsoleWriter>
        <x:Code><![CDATA[
                public static void Main(string[] args)
                {

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

Reply via email to