2005-07-11 Iain McCoy <iain@mccoy.id.au>
authorIain McCoy <iainmc@mono-cvs.ximian.com>
Wed, 13 Jul 2005 12:26:59 +0000 (12:26 -0000)
committerIain McCoy <iainmc@mono-cvs.ximian.com>
Wed, 13 Jul 2005 12:26:59 +0000 (12:26 -0000)
        * 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

mcs/class/PresentationFramework/ChangeLog
mcs/class/PresentationFramework/Makefile
mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
mcs/class/PresentationFramework/PresentationFramework_test.dll.sources [new file with mode: 0644]
mcs/class/PresentationFramework/System.Windows.Serialization/Mapper.cs
mcs/tools/xamlc/ChangeLog

index e10b953e243d9ab367c239663fad3b91da44b553..f456ff7d70668349a3c577afbc4ed1a5fda0fc9e 100644 (file)
@@ -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
index f04f16b745e6d88ba235fabb2a33b325812a3b73..85ee60e45cf5b87dd09f6a2fa8636300c287f986 100644 (file)
@@ -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
index b6939555538338b87ca438691782257203743f39..5a39087f1924d412daa865f0192227ed6279c026 100644 (file)
@@ -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)
index fb9f2a26b1898f838cede4fd5c84e94fea36d849..39bdcf453496ba8b096bf2665e6942622f3986dc 100644 (file)
@@ -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 (file)
index 0000000..1a4ffb8
--- /dev/null
@@ -0,0 +1 @@
+XamlParser.cs
index 3594d89887851337409a2d510b1b1d0a08770320..4f1683a52a565f5bb3b5142a0cbc62331de7d5bc 100644 (file)
@@ -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)
index 05f44e677dd4bd3bf0b432006e3bc4111e136a08..365f5a6da9272f7becf287c87d1c2c9b7929f5dd 100644 (file)
@@ -1,4 +1,4 @@
-2005-07-06  Iain McCoy  <iain@mccoy.id.au>
+2005-07-08  Iain McCoy  <iain@mccoy.id.au>
 
        * demo/runtimetest.xaml
          demo/runtimetest.cs,