From 8b779ce90b2d1606eb89501b6e53be4701776d5b Mon Sep 17 00:00:00 2001 From: Iain McCoy Date: Fri, 15 Jul 2005 07:49:27 +0000 Subject: 2005-07-15 Iain McCoy * 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 --- mcs/class/PresentationFramework/ChangeLog | 7 +++++ .../Mono.Windows.Serialization/ObjectWriter.cs | 34 ++++++++++++++++++---- .../System.Windows.Serialization/Mapper.cs | 7 +++-- 3 files changed, 40 insertions(+), 8 deletions(-) (limited to 'mcs/class/PresentationFramework') 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,3 +1,10 @@ +2005-07-15 Iain McCoy + + * 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 * Mono.Windows.Serialization/CodeWriter.cs: don't try to convert 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 -- cgit v1.2.3