diff options
author | Iain McCoy <iainmc@mono-cvs.ximian.com> | 2005-07-13 16:26:59 +0400 |
---|---|---|
committer | Iain McCoy <iainmc@mono-cvs.ximian.com> | 2005-07-13 16:26:59 +0400 |
commit | 48f16a8140726efea50d32676054a16f57d1650b (patch) | |
tree | a050bf01663c26358da23c5e7b58afb5219ef910 /mcs/class/PresentationFramework | |
parent | 2f70262c0c9879891894990400f8f4e18f7b88c2 (diff) |
2005-07-11 Iain McCoy <iain@mccoy.id.au>
* Makefile,
Test/XamlParser.cs: added a few tests
* Mono.Windows.Serialization/CodeWriter.cs,
Mono.Windows.Serialization/XamlParser.cs: fixed some bugs that the
new tests turned up
svn path=/trunk/mcs/; revision=47263
Diffstat (limited to 'mcs/class/PresentationFramework')
6 files changed, 52 insertions, 13 deletions
diff --git a/mcs/class/PresentationFramework/ChangeLog b/mcs/class/PresentationFramework/ChangeLog index e10b953e243..f456ff7d706 100644 --- a/mcs/class/PresentationFramework/ChangeLog +++ b/mcs/class/PresentationFramework/ChangeLog @@ -1,3 +1,11 @@ +2005-07-11 Iain McCoy <iain@mccoy.id.au> + + * Makefile, + Test/XamlParser.cs: added a few tests + * Mono.Windows.Serialization/CodeWriter.cs, + Mono.Windows.Serialization/XamlParser.cs: fixed some bugs that the + new tests turned up + 2005-07-08 Iain McCoy <iain@mccoy.id.au> * Mono.Windows.Serialization/ObjectWriter.cs: code to build objects at diff --git a/mcs/class/PresentationFramework/Makefile b/mcs/class/PresentationFramework/Makefile index f04f16b745e..85ee60e45cf 100644 --- a/mcs/class/PresentationFramework/Makefile +++ b/mcs/class/PresentationFramework/Makefile @@ -4,6 +4,15 @@ include ../../build/rules.make LIBRARY = PresentationFramework.dll LIB_MCS_FLAGS = -r:System.Xml.dll -r:WindowsBase.dll -r:System.dll -NO_TEST = yes +TEST_MCS_FLAGS = $(LIB_MCS_FLAGS) -r:TestVocab.dll -r:System.dll +TEST_MONO_PATH = . + +Test/XamlParser.cs: Test/TestVocab.dll + +Test/TestVocab.dll: ../../tools/xamlc/demo/TestVocab/*.cs + echo $(MONO_PATH) + (cd ../../tools/xamlc/demo; make TestVocab.dll) + cp ../../tools/xamlc/demo/TestVocab.dll Test/TestVocab.dll + cp Test/TestVocab.dll TestVocab.dll include ../../build/library.make diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs index b6939555538..5a39087f192 100644 --- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs +++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs @@ -61,6 +61,9 @@ namespace Mono.Windows.Serialization { // instance public void CreateTopLevel(Type parent, string className) { + if (className == null) { + className = "derived" + parent.Name; + } int endNamespaceName = className.LastIndexOf("."); string clrNamespace; if (endNamespaceName < 0) diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs index fb9f2a26b18..39bdcf45349 100644 --- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs +++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs @@ -52,20 +52,33 @@ namespace Mono.Windows.Serialization { public CurrentType type; } + private bool begun = false; + private ParserState currentState = null; private ArrayList oldStates = new ArrayList(); - public XamlParser(string filename, XamlWriter writer) + public XamlParser(string filename, XamlWriter writer) : this( + new XmlTextReader(filename), writer) { - reader = new XmlTextReader(filename); + } + + public XamlParser(TextReader reader, XamlWriter writer) : this( + new XmlTextReader(reader), writer) + { + } + + public XamlParser(XmlReader reader, XamlWriter writer) + { + this.reader = reader; this.writer = writer; } public void Parse() { while (reader.Read()) { - if (currentState != null && - currentState.type == CurrentType.Code) + if (begun && currentState == null) + throw new Exception("Too far: " + reader.NodeType + ", " + reader.Name); + if (currentState != null && currentState.type == CurrentType.Code) { if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "Code" && @@ -222,6 +235,10 @@ namespace Mono.Windows.Serialization { if (parent.GetInterface("System.Windows.Serialization.IAddChild") == null) {} //TODO: throw exception if (currentState == null) { + if (reader.GetAttribute("Name", XAML_NAMESPACE) != null) + throw new Exception("The XAML Name attribute can not be applied to top level elements\n"+ + "Do you mean the Class attribute?"); + begun = true; createTopLevel(parent.AssemblyQualifiedName, reader.GetAttribute("Class", XAML_NAMESPACE)); } else { string name = reader.GetAttribute("Name", XAML_NAMESPACE); @@ -256,9 +273,6 @@ namespace Mono.Windows.Serialization { currentState = new ParserState(); currentState.type = CurrentType.Object; currentState.obj = t; - if (className == null) { - className = "derived" + t.Name; - } writer.CreateTopLevel(t, className); } @@ -355,13 +369,12 @@ namespace Mono.Windows.Serialization { { if (currentState.type == CurrentType.Code) writer.CreateCode((string)currentState.obj); - if (currentState.type == CurrentType.Object) + else if (currentState.type == CurrentType.Object) writer.EndObject(); else if (currentState.type == CurrentType.Property) writer.EndProperty(); else if (currentState.type == CurrentType.DependencyProperty) writer.EndDependencyProperty(); - pop(); } @@ -375,7 +388,6 @@ namespace Mono.Windows.Serialization { int lastIndex = oldStates.Count - 1; currentState = (ParserState)oldStates[lastIndex]; oldStates.RemoveAt(lastIndex); - } } diff --git a/mcs/class/PresentationFramework/PresentationFramework_test.dll.sources b/mcs/class/PresentationFramework/PresentationFramework_test.dll.sources new file mode 100644 index 00000000000..1a4ffb83b0f --- /dev/null +++ b/mcs/class/PresentationFramework/PresentationFramework_test.dll.sources @@ -0,0 +1 @@ +XamlParser.cs diff --git a/mcs/class/PresentationFramework/System.Windows.Serialization/Mapper.cs b/mcs/class/PresentationFramework/System.Windows.Serialization/Mapper.cs index 3594d898878..4f1683a52a5 100644 --- a/mcs/class/PresentationFramework/System.Windows.Serialization/Mapper.cs +++ b/mcs/class/PresentationFramework/System.Windows.Serialization/Mapper.cs @@ -133,9 +133,15 @@ namespace System.Windows.Serialization { Assembly getAssembly(string name) { - if (assemblyPath[name] != null) + if (assemblyPath.ContainsKey(name)) name = (string)assemblyPath[name]; - return Assembly.Load(name); + Assembly result = Assembly.LoadFrom(name); + if (result == null) + result = Assembly.Load(name); + if (result == null) + throw new Exception("Could not find assembly with name " + name); + else + return result; } public void SetAssemblyPath(string assemblyName, string assemblyPath) |