diff options
author | Iain McCoy <iainmc@mono-cvs.ximian.com> | 2005-07-15 11:49:27 +0400 |
---|---|---|
committer | Iain McCoy <iainmc@mono-cvs.ximian.com> | 2005-07-15 11:49:27 +0400 |
commit | 8b779ce90b2d1606eb89501b6e53be4701776d5b (patch) | |
tree | 5a82f4c59112b7217aca95d7fc233ff77546e2e6 | |
parent | 5ebe857edd7aff8bb42acf89b4f554e6d78e3fbe (diff) |
2005-07-15 Iain McCoy <iain@mccoy.id.au>
* System.Windows.Serialization/Mapper.cs: make assembly loading more
resilient
* Mono.Windows.Serialization/ObjectWriter.cs: do conversions from
strings and support dependency properties
* demo/test.xaml: enhanced testing of complex objects as property
values and documented test file.
* demo/runtimetest.xaml: added dependency property test
svn path=/trunk/mcs/; revision=47329
-rw-r--r-- | mcs/class/PresentationFramework/ChangeLog | 7 | ||||
-rw-r--r-- | mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs | 34 | ||||
-rw-r--r-- | mcs/class/PresentationFramework/System.Windows.Serialization/Mapper.cs | 7 | ||||
-rw-r--r-- | mcs/tools/xamlc/ChangeLog | 6 | ||||
-rw-r--r-- | mcs/tools/xamlc/README | 7 | ||||
-rw-r--r-- | mcs/tools/xamlc/demo/runtimetest.xaml | 2 | ||||
-rw-r--r-- | mcs/tools/xamlc/demo/test.xaml | 30 |
7 files changed, 83 insertions, 10 deletions
diff --git a/mcs/class/PresentationFramework/ChangeLog b/mcs/class/PresentationFramework/ChangeLog index 35d15bee2e2..0bdd7cf8783 100644 --- a/mcs/class/PresentationFramework/ChangeLog +++ b/mcs/class/PresentationFramework/ChangeLog @@ -1,5 +1,12 @@ 2005-07-15 Iain McCoy <iain@mccoy.id.au> + * System.Windows.Serialization/Mapper.cs: make assembly loading more + resilient + * Mono.Windows.Serialization/ObjectWriter.cs: do conversions from + strings and support dependency properties + +2005-07-15 Iain McCoy <iain@mccoy.id.au> + * Mono.Windows.Serialization/CodeWriter.cs: don't try to convert objects into their parent types. diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs index f024812150b..67b988345fe 100644 --- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs +++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs @@ -32,6 +32,7 @@ using System.IO; using System.Collections; using System.CodeDom; using System.CodeDom.Compiler; +using System.ComponentModel; using System.Windows.Serialization; namespace Mono.Windows.Serialization { @@ -66,12 +67,18 @@ namespace Mono.Windows.Serialization { public void CreateDependencyProperty(Type attachedTo, string propertyName, Type propertyType) { - throw new NotImplementedException(); + objects.Add(attachedTo); + objects.Add(propertyName); } public void EndDependencyProperty() { - throw new NotImplementedException(); + object value = pop(); + string propertyName = (string)pop(); + Type attachedTo = (Type)pop(); + + MethodInfo setter = attachedTo.GetMethod("Set" + propertyName); + setter.Invoke(null, new object[] { objects[objects.Count - 1], value}); } public void CreateElementText(string text) @@ -96,11 +103,14 @@ namespace Mono.Windows.Serialization { public void CreatePropertyText(string text, Type propertyType) { - if (propertyType != typeof(string)) - throw new NotImplementedException(); + object value = text; + if (propertyType != typeof(string)) { + TypeConverter tc = TypeDescriptor.GetConverter(propertyType); + value = tc.ConvertFromString(text); + } PropertyInfo p = (PropertyInfo)objects[objects.Count-1]; object o = objects[objects.Count-2]; - p.SetValue(o, text, null); + p.SetValue(o, value, null); } public void CreatePropertyObject(Type type, string name) @@ -115,7 +125,12 @@ namespace Mono.Windows.Serialization { // top of stack is reference to an attached property public void CreateDependencyPropertyText(string text, Type propertyType) { - throw new NotImplementedException(); + object value = text; + if (propertyType != typeof(string)) { + TypeConverter tc = TypeDescriptor.GetConverter(propertyType); + value = tc.ConvertFromString(text); + } + objects.Add(value); } public void EndObject() @@ -141,5 +156,12 @@ namespace Mono.Windows.Serialization { { throw new NotImplementedException(); } + + private object pop() + { + object v = objects[objects.Count - 1]; + objects.RemoveAt(objects.Count - 1); + return v; + } } } diff --git a/mcs/class/PresentationFramework/System.Windows.Serialization/Mapper.cs b/mcs/class/PresentationFramework/System.Windows.Serialization/Mapper.cs index 4f1683a52a5..c4ee2af0379 100644 --- a/mcs/class/PresentationFramework/System.Windows.Serialization/Mapper.cs +++ b/mcs/class/PresentationFramework/System.Windows.Serialization/Mapper.cs @@ -135,9 +135,12 @@ namespace System.Windows.Serialization { { if (assemblyPath.ContainsKey(name)) name = (string)assemblyPath[name]; - Assembly result = Assembly.LoadFrom(name); - if (result == null) + Assembly result; + try { + result = Assembly.LoadFrom(name); + } catch { result = Assembly.Load(name); + } if (result == null) throw new Exception("Could not find assembly with name " + name); else diff --git a/mcs/tools/xamlc/ChangeLog b/mcs/tools/xamlc/ChangeLog index 7978e41854d..baaea480fce 100644 --- a/mcs/tools/xamlc/ChangeLog +++ b/mcs/tools/xamlc/ChangeLog @@ -1,5 +1,11 @@ 2005-07-15 Iain McCoy <iain@mccoy.id.au> + * demo/test.xaml: enhanced testing of complex objects as property + values and documented test file. + * demo/runtimetest.xaml: added dependency property test + +2005-07-15 Iain McCoy <iain@mccoy.id.au> + * demo/TestVocab/ConsoleValues.cs: Add ConsoleValueAppend to avoid resolving read value too early * demo/TestVocab/ConsoleWriter.cs: Use ConsoleValue as type of Text diff --git a/mcs/tools/xamlc/README b/mcs/tools/xamlc/README index 33f0b33f419..23616f60237 100644 --- a/mcs/tools/xamlc/README +++ b/mcs/tools/xamlc/README @@ -34,12 +34,19 @@ Hello World IT BEGINS! Hello World YYYI'm surrounded!ZZZ +What should I say? + +I say I say: INPUTINPUT +I say. + + Goodbye. Goodbye. Goodbye. Bye Bye + Hopefully you can work out how that is produced from the test.xaml file. In the same directory, "make run2" should demonstrate the runtime creation of diff --git a/mcs/tools/xamlc/demo/runtimetest.xaml b/mcs/tools/xamlc/demo/runtimetest.xaml index b449c3068d6..555e76dcdd9 100644 --- a/mcs/tools/xamlc/demo/runtimetest.xaml +++ b/mcs/tools/xamlc/demo/runtimetest.xaml @@ -3,7 +3,7 @@ <ConsoleApp xmlns="console" xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005" x:Class="DemoConsoleApp"> - <ConsoleWriter>IT BEGINS!</ConsoleWriter> + <ConsoleWriter ConsoleApp.Repetitions="2">IT BEGINS!</ConsoleWriter> <ConsoleWriter x:Name="_greeter" Text="Hello World" /> <ConsoleWriter> <ConsoleWriter.Text>Goodbye.</ConsoleWriter.Text> diff --git a/mcs/tools/xamlc/demo/test.xaml b/mcs/tools/xamlc/demo/test.xaml index d965c86cad4..2618fcee4b6 100644 --- a/mcs/tools/xamlc/demo/test.xaml +++ b/mcs/tools/xamlc/demo/test.xaml @@ -4,22 +4,50 @@ xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005" x:Class="DemoConsoleApp" SomethingHappened="printHi"> + <!-- create a ConsoleWriter and populate it with IAddChild --> <ConsoleWriter>IT BEGINS!</ConsoleWriter> + <!-- create a ConsoleWriter specifying a name and setting its text + property with an xml attribute --> <ConsoleWriter x:Name="_greeter" Text="Hello World" /> + <!-- create a ConsoleWriter with the text property again set with an + xml attribute but also set a property with a delegate type --> <ConsoleWriter Text="I'm surrounded!" Filter="stringFilter" /> + <!-- create a ConsoleReader and explicitly set its prompt to a + ConsoleWriter --> <ConsoleReader Variable="thingo"> <ConsoleReader.Prompt> <ConsoleWriter>What should I say?</ConsoleWriter> </ConsoleReader.Prompt> </ConsoleReader> + <!-- + create a ConsoleReader where a ConsoleWriter is implicitly created + and AddText called on it + NOT USED due to uncertainty about if this is an actual feature + <ConsoleReader Variable="thingo2"> + <ConsoleReader.Prompt>Then I shall say?</ConsoleReader.Prompt> + </ConsoleReader> + --> + <!-- Create a ConsoleWriter where a ConsoleValueVar object is created + and added as a child alongside text children --> + <ConsoleWriter> +I say I say: <ConsoleValueVar Variable="thingo" /> +I say. + </ConsoleWriter> + <!-- Explicitly set the ConsoleWriter's Text property to a + ConsoleValueVar instance --> <ConsoleWriter> - <ConsoleWriter.Text>I say: <ConsoleValueVar Variable="thingo" /></ConsoleWriter.Text> + <ConsoleWriter.Text><ConsoleValueVar Variable="thingo2" /></ConsoleWriter.Text> </ConsoleWriter> + <!-- Create a ConsoleWriter and set the ConsoleApp.Repetitions + dependency property as an element --> <ConsoleWriter> <ConsoleApp.Repetitions>3</ConsoleApp.Repetitions> <ConsoleWriter.Text>Goodbye.</ConsoleWriter.Text> </ConsoleWriter> + <!-- Create a ConsoleWriter and set the ConsoleApp.Repetitions + dependency property as an attribute --> <ConsoleWriter ConsoleApp.Repetitions="2">Bye</ConsoleWriter> + <!-- a fairly standard Code element --> <x:Code><![CDATA[ public static void Main(string[] args) { |