diff options
author | Iain McCoy <iainmc@mono-cvs.ximian.com> | 2005-07-08 16:32:27 +0400 |
---|---|---|
committer | Iain McCoy <iainmc@mono-cvs.ximian.com> | 2005-07-08 16:32:27 +0400 |
commit | 3b8170b02746dfc718c13e324730ed6e83fac5ad (patch) | |
tree | 36c69ade437e2793a5e6d080570b012a927b076a /mcs | |
parent | b1e4a4e3256614f4c180f0d150b593391ce447ae (diff) |
2005-07-06 Iain McCoy <iain@mccoy.id.au>
* demo/test.xaml: add use of x:Name attribute
* 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.
svn path=/trunk/mcs/; revision=47091
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/PresentationFramework/ChangeLog | 8 | ||||
-rw-r--r-- | mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs | 35 | ||||
-rw-r--r-- | mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs | 21 | ||||
-rw-r--r-- | mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs | 2 | ||||
-rw-r--r-- | mcs/tools/xamlc/ChangeLog | 4 | ||||
-rw-r--r-- | mcs/tools/xamlc/README | 3 | ||||
-rw-r--r-- | mcs/tools/xamlc/demo/test.xaml | 5 |
7 files changed, 53 insertions, 25 deletions
diff --git a/mcs/class/PresentationFramework/ChangeLog b/mcs/class/PresentationFramework/ChangeLog index 21baffd7d49..32741738996 100644 --- a/mcs/class/PresentationFramework/ChangeLog +++ b/mcs/class/PresentationFramework/ChangeLog @@ -1,3 +1,11 @@ +2005-07-08 Iain McCoy <iain@mccoy.id.au> + + * 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. + 2005-07-06 Iain McCoy <iain@mccoy.id.au> * Mono.Windows.Serialization/CodeWriter.cs: cleaned up a little, added diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs index 8ac2792deca..5ed0c3118fb 100644 --- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs +++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs @@ -89,13 +89,19 @@ namespace Mono.Windows.Serialization { // bottom of stack holds CodeVariableReferenceExpression // pushes a reference to the new current type - public void CreateObject(Type type) + public void CreateObject(Type type, string varName) { - string varName = Char.ToLower(type.Name[0]) + type.Name.Substring(1); - // make sure something sensible happens when class - // names start with a lowercase letter - if (varName == type.Name) - varName = "_" + varName; + bool isDefaultName; + if (varName == null) { + isDefaultName = true; + varName = Char.ToLower(type.Name[0]) + type.Name.Substring(1); + // make sure something sensible happens when class + // names start with a lowercase letter + if (varName == type.Name) + varName = "_" + varName; + } else { + isDefaultName = false; + } if (!nameClashes.ContainsKey(varName)) nameClashes[varName] = 0; @@ -104,16 +110,23 @@ namespace Mono.Windows.Serialization { varName += (int)nameClashes[varName]; } - CodeVariableDeclarationStatement declaration = - new CodeVariableDeclarationStatement(type, - varName, - new CodeObjectCreateExpression(type)); + + if (isDefaultName) { + CodeVariableDeclarationStatement declaration = + new CodeVariableDeclarationStatement(type, + varName, + new CodeObjectCreateExpression(type)); + constructor.Statements.Add(declaration); + } else { + CodeMemberField declaration = new CodeMemberField(type, varName); + declaration.InitExpression = new CodeObjectCreateExpression(type); + this.type.Members.Add(declaration); + } CodeVariableReferenceExpression varRef = new CodeVariableReferenceExpression(varName); CodeMethodInvokeExpression addChild = new CodeMethodInvokeExpression( (CodeExpression)objects[objects.Count - 1], "AddChild", varRef); - constructor.Statements.Add(declaration); constructor.Statements.Add(addChild); objects.Add(varRef); } diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs index 749f9feefb7..369c6532fea 100644 --- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs +++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs @@ -242,17 +242,18 @@ namespace Mono.Windows.Serialization { void parseObjectElement() { Type parent; - string objectName = null; bool isEmpty = reader.IsEmptyElement; parent = mapper.GetType(reader.NamespaceURI, reader.Name); - objectName = reader.GetAttribute("Class", XAML_NAMESPACE); if (parent.GetInterface("System.Windows.Serialization.IAddChild") == null) {} //TODO: throw exception if (currentState == null) { - createTopLevel(parent.AssemblyQualifiedName, objectName); + createTopLevel(parent.AssemblyQualifiedName, reader.GetAttribute("Class", XAML_NAMESPACE)); } else { - addChild(parent); + string name = reader.GetAttribute("Name", XAML_NAMESPACE); + if (name == null) + name = reader.GetAttribute("Name", reader.NamespaceURI); + addChild(parent, name); } if (reader.MoveToFirstAttribute()) { @@ -275,21 +276,21 @@ namespace Mono.Windows.Serialization { } } - void createTopLevel(string parentName, string objectName) + void createTopLevel(string parentName, string className) { Type t = Type.GetType(parentName); currentState = new ParserState(); currentState.type = CurrentType.Object; currentState.obj = t; - if (objectName == null) { - objectName = "derived" + t.Name; + if (className == null) { + className = "derived" + t.Name; } - writer.CreateTopLevel(t, objectName); + writer.CreateTopLevel(t, className); } - void addChild(Type type) + void addChild(Type type, string objectName) { - writer.CreateObject(type); + writer.CreateObject(type, objectName); oldStates.Add(currentState); currentState = new ParserState(); currentState.type = CurrentType.Object; diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs index 0c93c74c955..38d7170c94a 100644 --- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs +++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs @@ -33,7 +33,7 @@ namespace Mono.Windows.Serialization { public interface XamlWriter { void CreateTopLevel(Type parent, string className); - void CreateObject(Type type); + void CreateObject(Type type, string name); void CreateElementText(string text); void EndObject(); diff --git a/mcs/tools/xamlc/ChangeLog b/mcs/tools/xamlc/ChangeLog index 74749a7b94e..f757c0e7662 100644 --- a/mcs/tools/xamlc/ChangeLog +++ b/mcs/tools/xamlc/ChangeLog @@ -1,5 +1,9 @@ 2005-07-06 Iain McCoy <iain@mccoy.id.au> + * demo/test.xaml: add use of x:Name attribute + +2005-07-06 Iain McCoy <iain@mccoy.id.au> + * xamlc.cs: add support for emitting classes with the partial modifier set diff --git a/mcs/tools/xamlc/README b/mcs/tools/xamlc/README index 226e4eaf8d7..46a40e0045b 100644 --- a/mcs/tools/xamlc/README +++ b/mcs/tools/xamlc/README @@ -30,6 +30,7 @@ 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: +Hello World IT BEGINS! Hello World YYYI'm surrounded!ZZZ @@ -39,4 +40,4 @@ Goodbye. Bye Bye -You should be able to see how that's made from the included test.xaml file +Hopefully you can work out how that is produced from the test.xaml file. diff --git a/mcs/tools/xamlc/demo/test.xaml b/mcs/tools/xamlc/demo/test.xaml index 23a60cd7ab9..27119fc94a8 100644 --- a/mcs/tools/xamlc/demo/test.xaml +++ b/mcs/tools/xamlc/demo/test.xaml @@ -5,7 +5,7 @@ x:Class="DemoConsoleApp" SomethingHappened="printHi"> <ConsoleWriter>IT BEGINS!</ConsoleWriter> - <ConsoleWriter Text="Hello World" /> + <ConsoleWriter x:Name="_greeter" Text="Hello World" /> <ConsoleWriter Text="I'm surrounded!" Filter="stringFilter" /> <ConsoleWriter> <ConsoleApp.Repetitions>3</ConsoleApp.Repetitions> @@ -15,7 +15,8 @@ <x:Code><![CDATA[ public static void Main(string[] args) { - Xaml.TestVocab.Console.ConsoleApp c = new DemoConsoleApp(); + DemoConsoleApp c = new DemoConsoleApp(); + c._greeter.Run(); c.Run(); } |