From: Iain McCoy Date: Fri, 26 Aug 2005 11:15:34 +0000 (-0000) Subject: 2005-08-26 Iain McCoy X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=ffb845b352dadf2a085b2b58aa3cb6c5d5ae4464;hp=-c;p=mono.git 2005-08-26 Iain McCoy * demo/runtimetest.cs: use the newly-renamed Parser class instead of the interim ObjectWriter 2005-08-24 Iain McCoy * Mono.Windows.Serialization/ObjectWriter.cs, System.Windows.Serialization/Parser.cs: renamed ObjectWriter to Parser, made interface more similar * Test/ObjectWriter.cs: changed to test the new Parser class 2005-08-24 Iain McCoy * Mono.Windows.Serialization/XamlParser.cs: make internal * Mono.Windows.Serialization/CodeWriter.cs: add private member so that the tests can get at the type for XamlParser * Test/XamlParser.cs: use reflection to get the XamlParser type out of CodeWriter, create an instance of it and get nodes from it svn path=/trunk/mcs/; revision=48885 --- ffb845b352dadf2a085b2b58aa3cb6c5d5ae4464 diff --combined mcs/class/PresentationFramework/ChangeLog index 77bc2be83da,77bc2be83da..4e73cfed51d --- a/mcs/class/PresentationFramework/ChangeLog +++ b/mcs/class/PresentationFramework/ChangeLog @@@ -1,3 -1,3 +1,18 @@@ ++2005-08-24 Iain McCoy ++ ++ * Mono.Windows.Serialization/ObjectWriter.cs, ++ System.Windows.Serialization/Parser.cs: renamed ObjectWriter to ++ Parser, made interface more similar ++ * Test/ObjectWriter.cs: changed to test the new Parser class ++ ++2005-08-24 Iain McCoy ++ ++ * Mono.Windows.Serialization/XamlParser.cs: make internal ++ * Mono.Windows.Serialization/CodeWriter.cs: add private member so that ++ the tests can get at the type for XamlParser ++ * Test/XamlParser.cs: use reflection to get the XamlParser type out of ++ CodeWriter, create an instance of it and get nodes from it ++ 2005-08-23 Iain McCoy * System.Windows.Serialization/XamlParser.cs: rearrange class so that diff --combined mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs index 244c321857c,244c321857c..cf34fe2098a --- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs +++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs @@@ -51,6 -51,6 +51,8 @@@ namespace Mono.Windows.Serialization CodeTypeDeclaration type; CodeConstructor constructor; ++ private static readonly Type xamlParserType = typeof(XamlParser); ++ public static string Parse(XmlTextReader reader, ICodeGenerator generator, bool isPartial) { CodeWriter cw = new CodeWriter(reader, generator, isPartial); diff --combined mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs index c078cb0763e,c078cb0763e..00000000000 deleted file mode 100644,100644 --- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs +++ /dev/null @@@ -1,270 -1,270 +1,0 @@@ --// --// CodeWriter.cs --// --// Author: --// Iain McCoy (iain@mccoy.id.au) --// --// (C) 2005 Iain McCoy --// --// Permission is hereby granted, free of charge, to any person obtaining --// a copy of this software and associated documentation files (the --// "Software"), to deal in the Software without restriction, including --// without limitation the rights to use, copy, modify, merge, publish, --// distribute, sublicense, and/or sell copies of the Software, and to --// permit persons to whom the Software is furnished to do so, subject to --// the following conditions: --// --// The above copyright notice and this permission notice shall be --// included in all copies or substantial portions of the Software. --// --// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, --// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND --// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE --// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION --// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION --// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --// -- --using System; --using System.Reflection; --using System.IO; --using System.Collections; --using System.CodeDom; --using System.CodeDom.Compiler; --using System.ComponentModel; --using System.Diagnostics; --using System.Windows; --using System.Windows.Serialization; --using System.Xml; -- --namespace Mono.Windows.Serialization { -- public class ObjectWriter { -- public object instance; -- ArrayList objects = new ArrayList(); -- -- public static object Parse(XmlTextReader reader) -- { -- ObjectWriter ow = new ObjectWriter(reader); -- return ow.instance; -- } -- private ObjectWriter(XmlTextReader reader) -- { -- XamlParser p = new XamlParser(reader); -- XamlNode n; -- while (true) { -- n = p.GetNextNode(); -- if (n == null) -- break; -- Debug.WriteLine("ObjectWriter: INCOMING " + n.GetType()); -- if (n is XamlDocumentStartNode) { -- Debug.WriteLine("ObjectWriter: document begins"); -- // do nothing -- } else if (n is XamlElementStartNode && n.Depth == 0) { -- Debug.WriteLine("ObjectWriter: element begins as top-level"); -- CreateTopLevel(((XamlElementStartNode)n).ElementType, ((XamlElementStartNode)n).name); -- } else if (n is XamlElementStartNode && peek() is PropertyInfo) { -- Debug.WriteLine("ObjectWriter: element begins as property value"); -- CreatePropertyObject(((XamlElementStartNode)n).ElementType, ((XamlElementStartNode)n).name); -- } else if (n is XamlElementStartNode) { -- Debug.WriteLine("ObjectWriter: element begins"); -- CreateObject(((XamlElementStartNode)n).ElementType, ((XamlElementStartNode)n).name); -- } else if (n is XamlPropertyNode && ((XamlPropertyNode)n).PropInfo != null) { -- Debug.WriteLine("ObjectWriter: normal property begins"); -- CreateProperty(((XamlPropertyNode)n).PropInfo); -- } else if (n is XamlPropertyNode && ((XamlPropertyNode)n).DP != null) { -- Debug.WriteLine("ObjectWriter: dependency property begins"); -- DependencyProperty dp = ((XamlPropertyNode)n).DP; -- Type typeAttachedTo = dp.OwnerType; -- string propertyName = ((XamlPropertyNode)n).PropertyName; -- -- CreateDependencyProperty(typeAttachedTo, propertyName, dp.PropertyType); -- } else if (n is XamlClrEventNode) { -- Debug.WriteLine("ObjectWriter: event"); -- CreateEvent((EventInfo)((XamlClrEventNode)n).EventMember); -- CreateEventDelegate(((XamlClrEventNode)n).Value, ((EventInfo)((XamlClrEventNode)n).EventMember).EventHandlerType); -- EndEvent(); -- -- } else if (n is XamlTextNode && ((XamlTextNode)n).mode == XamlParseMode.Object){ -- Debug.WriteLine("ObjectWriter: text for object"); -- CreateObjectText(((XamlTextNode)n).TextContent); -- } else if (n is XamlTextNode && ((XamlTextNode)n).mode == XamlParseMode.Property){ -- Debug.WriteLine("ObjectWriter: text for property"); -- Debug.WriteLine("THINGTYPE = " + peek().GetType()); -- CreatePropertyText(((XamlTextNode)n).TextContent, ((PropertyInfo)peek()).PropertyType); -- EndProperty(); -- } else if (n is XamlTextNode && ((XamlTextNode)n).mode == XamlParseMode.DependencyProperty){ -- Debug.WriteLine("ObjectWriter: text for dependency property"); -- string propertyName = (string)peek(); -- Type attachedTo = (Type)peek(1); -- CreateDependencyPropertyText(((XamlTextNode)n).TextContent, ((DependencyProperty)attachedTo.GetField(propertyName + "Property").GetValue(null)).PropertyType); -- EndDependencyProperty(); -- } else if (n is XamlPropertyComplexEndNode) { -- Debug.WriteLine("ObjectWriter: end complex property"); -- Debug.WriteLine("ObjectWriter: final type is " + ((XamlPropertyComplexEndNode)n).finalType); -- EndPropertyObject(((XamlPropertyComplexEndNode)n).finalType); -- EndProperty(); -- } else if (n is XamlElementEndNode) { -- Debug.WriteLine("ObjectWriter: end element"); -- if (!((XamlElementEndNode)n).propertyObject) -- EndObject(); -- } else if (n is XamlDocumentEndNode) { -- Debug.WriteLine("ObjectWriter: end document"); -- Finish(); -- } else { -- throw new Exception("Unknown node " + n.GetType()); -- } -- } -- } -- -- -- public void CreateTopLevel(Type parent, string className) -- { -- instance = Activator.CreateInstance(parent); -- push(instance); -- } -- -- public void CreateObject(Type type, string varName) -- { -- Object o = Activator.CreateInstance(type); -- ((IAddChild)peek()).AddChild(o); -- push(o); -- } -- -- public void CreateProperty(PropertyInfo property) -- { -- push(property); -- } -- -- // top of stack is a reference to an object -- // pushes a reference to the event -- public void CreateEvent(EventInfo evt) -- { -- push(evt); -- } -- -- public void CreateDependencyProperty(Type attachedTo, string propertyName, Type propertyType) -- { -- push(attachedTo); -- push(propertyName); -- } -- -- public void EndDependencyProperty() -- { -- object value = pop(); -- string propertyName = (string)pop(); -- Type attachedTo = (Type)pop(); -- -- MethodInfo setter = attachedTo.GetMethod("Set" + propertyName); -- setter.Invoke(null, new object[] { peek(), value}); -- } -- -- public void CreateObjectText(string text) -- { -- ((IAddChild)peek()).AddText(text); -- } -- -- // top of stack is reference to an event -- public void CreateEventDelegate(string functionName, Type eventDelegateType) -- { -- EventInfo e = (EventInfo)peek(); -- object o = peek(1); -- e.AddEventHandler(o, Delegate.CreateDelegate(o.GetType(), o, functionName)); -- } -- // top of stack is reference to a property -- public void CreatePropertyDelegate(string functionName, Type propertyType) -- { -- PropertyInfo p = (PropertyInfo)peek(); -- object o = peek(1); -- p.SetValue(o, Delegate.CreateDelegate(o.GetType(), o, functionName), null); -- } -- -- public void CreatePropertyText(string text, Type propertyType) -- { -- object value = text; -- if (propertyType != typeof(string)) { -- TypeConverter tc = TypeDescriptor.GetConverter(propertyType); -- value = tc.ConvertFromString(text); -- } -- PropertyInfo p = (PropertyInfo)peek(); -- object o = peek(1); -- p.SetValue(o, value, null); -- } -- -- public void CreatePropertyObject(Type type, string name) -- { -- object value = Activator.CreateInstance(type); -- Debug.WriteLine("ObjectWriter CREATING PROPERTY OBJECT of type" + type); -- push(value); -- } -- public void EndPropertyObject(Type destType) -- { -- object value = pop(); -- Type sourceType = value.GetType(); -- Debug.WriteLine("ObjectWriter: EndPropertyObject has a " + value + value.GetType() + ", needs a " + destType); -- if (destType != sourceType && !sourceType.IsSubclassOf(destType)) { -- TypeConverter tc = TypeDescriptor.GetConverter(destType); -- value = tc.ConvertFrom(value); -- } -- PropertyInfo p = (PropertyInfo)peek(); -- object o = peek(1); -- p.SetValue(o, value, null); -- } -- -- // top of stack is reference to an attached property -- public void CreateDependencyPropertyText(string text, Type propertyType) -- { -- object value = text; -- if (propertyType != typeof(string)) { -- TypeConverter tc = TypeDescriptor.GetConverter(propertyType); -- value = tc.ConvertFromString(text); -- } -- push(value); -- } -- -- public void EndObject() -- { -- pop(); -- } -- -- public void EndProperty() -- { -- pop(); -- } -- -- public void EndEvent() -- { -- pop(); -- } -- -- public void Finish() -- { -- } -- -- public void CreateCode(string code) -- { -- throw new NotImplementedException(); -- } -- -- private object peek() -- { -- return peek(0); -- } -- private object peek(int i) -- { -- return objects[objects.Count - 1 - i]; -- } -- private object pop() -- { -- object v = objects[objects.Count - 1]; -- objects.RemoveAt(objects.Count - 1); -- Debug.WriteLine("ObjectWriter POPPING"); -- return v; -- } -- private void push(object v) -- { -- Debug.WriteLine("ObjectWriter PUSHING " + v); -- objects.Add(v); -- } -- } --} diff --combined mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs index 4a96b7e2482,4a96b7e2482..b7702f792d5 --- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs +++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs @@@ -37,7 -37,7 +37,7 @@@ using System.Windows using System.Windows.Serialization; namespace Mono.Windows.Serialization { -- public class XamlParser { ++ internal class XamlParser { public const string XAML_NAMESPACE = "http://schemas.microsoft.com/winfx/xaml/2005"; private Mapper mapper = new Mapper(new string[] { }); private XmlTextReader reader; diff --combined mcs/class/PresentationFramework/PresentationFramework.dll.sources index 796cdc5ace6,796cdc5ace6..a76d924c5b2 --- a/mcs/class/PresentationFramework/PresentationFramework.dll.sources +++ b/mcs/class/PresentationFramework/PresentationFramework.dll.sources @@@ -1,11 -1,11 +1,11 @@@ System.Windows.Serialization/IAddChild.cs System.Windows.Serialization/Mapper.cs System.Windows.Serialization/NamespaceMapEntry.cs ++System.Windows.Serialization/Parser.cs System.Windows.Serialization/XamlNodeType.cs System.Windows.Serialization/XamlParseMode.cs System.Windows.Serialization/BamlAttributeUsage.cs Mono.Windows.Serialization/CodeWriter.cs --Mono.Windows.Serialization/ObjectWriter.cs Mono.Windows.Serialization/Exceptions.cs Mono.Windows.Serialization/XamlParser.cs Mono.Windows.Serialization/IXamlWriter.cs diff --combined mcs/class/PresentationFramework/System.Windows.Serialization/Parser.cs index 00000000000,00000000000..3b50d5c8dd2 new file mode 100644 --- /dev/null +++ b/mcs/class/PresentationFramework/System.Windows.Serialization/Parser.cs @@@ -1,0 -1,0 +1,275 @@@ ++// ++// CodeWriter.cs ++// ++// Author: ++// Iain McCoy (iain@mccoy.id.au) ++// ++// (C) 2005 Iain McCoy ++// ++// Permission is hereby granted, free of charge, to any person obtaining ++// a copy of this software and associated documentation files (the ++// "Software"), to deal in the Software without restriction, including ++// without limitation the rights to use, copy, modify, merge, publish, ++// distribute, sublicense, and/or sell copies of the Software, and to ++// permit persons to whom the Software is furnished to do so, subject to ++// the following conditions: ++// ++// The above copyright notice and this permission notice shall be ++// included in all copies or substantial portions of the Software. ++// ++// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ++// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ++// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ++// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE ++// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION ++// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION ++// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++// ++ ++using System; ++using System.Reflection; ++using System.IO; ++using System.Collections; ++using System.CodeDom; ++using System.CodeDom.Compiler; ++using System.ComponentModel; ++using System.Diagnostics; ++using System.Windows; ++using Mono.Windows.Serialization; ++using System.Xml; ++ ++namespace System.Windows.Serialization { ++ public class Parser { ++ private object instance; ++ ArrayList objects = new ArrayList(); ++ ++ public static object LoadXml(Stream s) ++ { ++ return LoadXml(new XmlTextReader(s)); ++ } ++ // TODO: this should take a XmlReader in order to be same as MSFT ++ public static object LoadXml(XmlTextReader reader) ++ { ++ Parser r = new Parser(reader); ++ return r.instance; ++ } ++ private Parser(XmlTextReader reader) ++ { ++ XamlParser p = new XamlParser(reader); ++ XamlNode n; ++ while (true) { ++ n = p.GetNextNode(); ++ if (n == null) ++ break; ++ Debug.WriteLine("ObjectWriter: INCOMING " + n.GetType()); ++ if (n is XamlDocumentStartNode) { ++ Debug.WriteLine("ObjectWriter: document begins"); ++ // do nothing ++ } else if (n is XamlElementStartNode && n.Depth == 0) { ++ Debug.WriteLine("ObjectWriter: element begins as top-level"); ++ CreateTopLevel(((XamlElementStartNode)n).ElementType, ((XamlElementStartNode)n).name); ++ } else if (n is XamlElementStartNode && peek() is PropertyInfo) { ++ Debug.WriteLine("ObjectWriter: element begins as property value"); ++ CreatePropertyObject(((XamlElementStartNode)n).ElementType, ((XamlElementStartNode)n).name); ++ } else if (n is XamlElementStartNode) { ++ Debug.WriteLine("ObjectWriter: element begins"); ++ CreateObject(((XamlElementStartNode)n).ElementType, ((XamlElementStartNode)n).name); ++ } else if (n is XamlPropertyNode && ((XamlPropertyNode)n).PropInfo != null) { ++ Debug.WriteLine("ObjectWriter: normal property begins"); ++ CreateProperty(((XamlPropertyNode)n).PropInfo); ++ } else if (n is XamlPropertyNode && ((XamlPropertyNode)n).DP != null) { ++ Debug.WriteLine("ObjectWriter: dependency property begins"); ++ DependencyProperty dp = ((XamlPropertyNode)n).DP; ++ Type typeAttachedTo = dp.OwnerType; ++ string propertyName = ((XamlPropertyNode)n).PropertyName; ++ ++ CreateDependencyProperty(typeAttachedTo, propertyName, dp.PropertyType); ++ } else if (n is XamlClrEventNode) { ++ Debug.WriteLine("ObjectWriter: event"); ++ CreateEvent((EventInfo)((XamlClrEventNode)n).EventMember); ++ CreateEventDelegate(((XamlClrEventNode)n).Value, ((EventInfo)((XamlClrEventNode)n).EventMember).EventHandlerType); ++ EndEvent(); ++ ++ } else if (n is XamlTextNode && ((XamlTextNode)n).mode == XamlParseMode.Object){ ++ Debug.WriteLine("ObjectWriter: text for object"); ++ CreateObjectText(((XamlTextNode)n).TextContent); ++ } else if (n is XamlTextNode && ((XamlTextNode)n).mode == XamlParseMode.Property){ ++ Debug.WriteLine("ObjectWriter: text for property"); ++ Debug.WriteLine("THINGTYPE = " + peek().GetType()); ++ CreatePropertyText(((XamlTextNode)n).TextContent, ((PropertyInfo)peek()).PropertyType); ++ EndProperty(); ++ } else if (n is XamlTextNode && ((XamlTextNode)n).mode == XamlParseMode.DependencyProperty){ ++ Debug.WriteLine("ObjectWriter: text for dependency property"); ++ string propertyName = (string)peek(); ++ Type attachedTo = (Type)peek(1); ++ CreateDependencyPropertyText(((XamlTextNode)n).TextContent, ((DependencyProperty)attachedTo.GetField(propertyName + "Property").GetValue(null)).PropertyType); ++ EndDependencyProperty(); ++ } else if (n is XamlPropertyComplexEndNode) { ++ Debug.WriteLine("ObjectWriter: end complex property"); ++ Debug.WriteLine("ObjectWriter: final type is " + ((XamlPropertyComplexEndNode)n).finalType); ++ EndPropertyObject(((XamlPropertyComplexEndNode)n).finalType); ++ EndProperty(); ++ } else if (n is XamlElementEndNode) { ++ Debug.WriteLine("ObjectWriter: end element"); ++ if (!((XamlElementEndNode)n).propertyObject) ++ EndObject(); ++ } else if (n is XamlDocumentEndNode) { ++ Debug.WriteLine("ObjectWriter: end document"); ++ Finish(); ++ } else { ++ throw new Exception("Unknown node " + n.GetType()); ++ } ++ } ++ } ++ ++ ++ public void CreateTopLevel(Type parent, string className) ++ { ++ instance = Activator.CreateInstance(parent); ++ push(instance); ++ } ++ ++ public void CreateObject(Type type, string varName) ++ { ++ Object o = Activator.CreateInstance(type); ++ ((IAddChild)peek()).AddChild(o); ++ push(o); ++ } ++ ++ public void CreateProperty(PropertyInfo property) ++ { ++ push(property); ++ } ++ ++ // top of stack is a reference to an object ++ // pushes a reference to the event ++ public void CreateEvent(EventInfo evt) ++ { ++ push(evt); ++ } ++ ++ public void CreateDependencyProperty(Type attachedTo, string propertyName, Type propertyType) ++ { ++ push(attachedTo); ++ push(propertyName); ++ } ++ ++ public void EndDependencyProperty() ++ { ++ object value = pop(); ++ string propertyName = (string)pop(); ++ Type attachedTo = (Type)pop(); ++ ++ MethodInfo setter = attachedTo.GetMethod("Set" + propertyName); ++ setter.Invoke(null, new object[] { peek(), value}); ++ } ++ ++ public void CreateObjectText(string text) ++ { ++ ((IAddChild)peek()).AddText(text); ++ } ++ ++ // top of stack is reference to an event ++ public void CreateEventDelegate(string functionName, Type eventDelegateType) ++ { ++ EventInfo e = (EventInfo)peek(); ++ object o = peek(1); ++ e.AddEventHandler(o, Delegate.CreateDelegate(o.GetType(), o, functionName)); ++ } ++ // top of stack is reference to a property ++ public void CreatePropertyDelegate(string functionName, Type propertyType) ++ { ++ PropertyInfo p = (PropertyInfo)peek(); ++ object o = peek(1); ++ p.SetValue(o, Delegate.CreateDelegate(o.GetType(), o, functionName), null); ++ } ++ ++ public void CreatePropertyText(string text, Type propertyType) ++ { ++ object value = text; ++ if (propertyType != typeof(string)) { ++ TypeConverter tc = TypeDescriptor.GetConverter(propertyType); ++ value = tc.ConvertFromString(text); ++ } ++ PropertyInfo p = (PropertyInfo)peek(); ++ object o = peek(1); ++ p.SetValue(o, value, null); ++ } ++ ++ public void CreatePropertyObject(Type type, string name) ++ { ++ object value = Activator.CreateInstance(type); ++ Debug.WriteLine("ObjectWriter CREATING PROPERTY OBJECT of type" + type); ++ push(value); ++ } ++ public void EndPropertyObject(Type destType) ++ { ++ object value = pop(); ++ Type sourceType = value.GetType(); ++ Debug.WriteLine("ObjectWriter: EndPropertyObject has a " + value + value.GetType() + ", needs a " + destType); ++ if (destType != sourceType && !sourceType.IsSubclassOf(destType)) { ++ TypeConverter tc = TypeDescriptor.GetConverter(destType); ++ value = tc.ConvertFrom(value); ++ } ++ PropertyInfo p = (PropertyInfo)peek(); ++ object o = peek(1); ++ p.SetValue(o, value, null); ++ } ++ ++ // top of stack is reference to an attached property ++ public void CreateDependencyPropertyText(string text, Type propertyType) ++ { ++ object value = text; ++ if (propertyType != typeof(string)) { ++ TypeConverter tc = TypeDescriptor.GetConverter(propertyType); ++ value = tc.ConvertFromString(text); ++ } ++ push(value); ++ } ++ ++ public void EndObject() ++ { ++ pop(); ++ } ++ ++ public void EndProperty() ++ { ++ pop(); ++ } ++ ++ public void EndEvent() ++ { ++ pop(); ++ } ++ ++ public void Finish() ++ { ++ } ++ ++ public void CreateCode(string code) ++ { ++ throw new NotImplementedException(); ++ } ++ ++ private object peek() ++ { ++ return peek(0); ++ } ++ private object peek(int i) ++ { ++ return objects[objects.Count - 1 - i]; ++ } ++ private object pop() ++ { ++ object v = objects[objects.Count - 1]; ++ objects.RemoveAt(objects.Count - 1); ++ Debug.WriteLine("ObjectWriter POPPING"); ++ return v; ++ } ++ private void push(object v) ++ { ++ Debug.WriteLine("ObjectWriter PUSHING " + v); ++ objects.Add(v); ++ } ++ } ++} diff --combined mcs/class/PresentationFramework/Test/ObjectWriter.cs index 73618b8c251,73618b8c251..887ae575d4f --- a/mcs/class/PresentationFramework/Test/ObjectWriter.cs +++ b/mcs/class/PresentationFramework/Test/ObjectWriter.cs @@@ -1,5 -1,5 +1,5 @@@ // --// ObjectWriter.cs - NUnit Test Cases for the xaml object builder ++// Parser.cs - NUnit Test Cases for the xaml object builder // // Author: // Iain McCoy (iain@mccoy.id.au) @@@ -37,13 -37,13 +37,14 @@@ using System.Reflection using System.Windows; using System.CodeDom.Compiler; using Mono.Windows.Serialization; ++using System.Windows.Serialization; using Xaml.TestVocab.Console; namespace MonoTests.System.Windows.Serialization { [TestFixture] --public class ObjectWriterTest { ++public class ParserTest { string code; [SetUp] @@@ -179,7 -179,7 +180,7 @@@ private void compare(object expected) { string mapping = "\n"; -- object o = ObjectWriter.Parse(new XmlTextReader(new StringReader(mapping + code))); ++ object o = Parser.LoadXml(new XmlTextReader(new StringReader(mapping + code))); Assert.AreEqual(expected, o); } diff --combined mcs/class/PresentationFramework/Test/XamlParser.cs index d70bce4e17f,d70bce4e17f..68b75684c7b --- a/mcs/class/PresentationFramework/Test/XamlParser.cs +++ b/mcs/class/PresentationFramework/Test/XamlParser.cs @@@ -56,9 -56,9 +56,10 @@@ public class XamlParserTest private void makeGoBang(string s) { XamlNode n; -- XamlParser p = new XamlParser(new StringReader(s)); ++ object p = buildParser(new StringReader(s)); do { -- n = p.GetNextNode(); ++ n = getNextNode(p); ++// Process.Start("xmessage " + n.GetType()); } while (!(n is XamlDocumentEndNode)); } @@@ -75,20 -75,20 +76,20 @@@ { string s = ""; XamlNode n; -- XamlParser p = new XamlParser(new StringReader(MAPPING + s)); ++ object p = buildParser(new StringReader(MAPPING + s)); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode, "A1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "B1"); Assert.AreEqual(0, n.Depth, "B2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp), "B3"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "C1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode, "D1"); } @@@ -125,21 -125,21 +126,21 @@@ string s = "\n"+ ""; XamlNode n; -- XamlParser p = new XamlParser(new StringReader(MAPPING + s)); ++ object p = buildParser(new StringReader(MAPPING + s)); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode, "A1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "B1"); Assert.AreEqual(0, n.Depth, "B2"); Assert.AreEqual("nnn", ((XamlElementStartNode)n).name, "B3"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp), "B4"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "C1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode, "D1"); } @@@ -160,28 -160,28 +161,28 @@@ ""; XamlNode n; -- XamlParser p = new XamlParser(new StringReader(MAPPING + s)); ++ object p = buildParser(new StringReader(MAPPING + s)); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode); Assert.AreEqual(n.Depth, 0); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp)); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode); Assert.AreEqual(n.Depth, 1); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleWriter)); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode); } @@@ -194,29 -194,29 +195,29 @@@ ""; XamlNode n; -- XamlParser p = new XamlParser(new StringReader(MAPPING + s)); ++ object p = buildParser(new StringReader(MAPPING + s)); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode, "A1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "B1"); Assert.AreEqual(n.Depth, 0, "B2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp), "B3"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "C1"); Assert.AreEqual(1, n.Depth, "C2"); Assert.AreEqual("XXX", ((XamlElementStartNode)n).name, "C3"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleWriter), "C4"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "D1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "E1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode, "F1"); } @@@ -251,32 -251,32 +252,32 @@@ ""; XamlNode n; -- XamlParser p = new XamlParser(new StringReader(MAPPING + s)); ++ object p = buildParser(new StringReader(MAPPING + s)); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode); Assert.AreEqual(n.Depth, 0); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp)); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode); Assert.AreEqual(n.Depth, 1); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleWriter)); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlTextNode); Assert.AreEqual(((XamlTextNode)n).TextContent, "Hello"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode); } @@@ -289,7 -289,7 +290,7 @@@ ""; XamlNode n; -- XamlParser p = new XamlParser(new StringReader(MAPPING + s)); ++ object p = buildParser(new StringReader(MAPPING + s)); basicPropertyTestStream(p, 0); } @@@ -302,45 -302,45 +303,45 @@@ "Hello\n" + "\n" + ""; -- XamlParser p = new XamlParser(new StringReader(MAPPING + s)); ++ object p = buildParser(new StringReader(MAPPING + s)); basicPropertyTestStream(p, 1); } -- private void basicPropertyTestStream(XamlParser p, int depthIncreaseForProperty) ++ private void basicPropertyTestStream(object p, int depthIncreaseForProperty) { XamlNode n; -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode, "A1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "B1"); Assert.AreEqual(0, n.Depth, "B2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp), "B3"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "C1"); Assert.AreEqual(1, n.Depth, "C2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleWriter), "C3"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlPropertyNode, "D1"); Assert.AreEqual(1 + depthIncreaseForProperty, n.Depth, "D2"); Assert.AreEqual(((XamlPropertyNode)n).PropInfo, typeof(ConsoleWriter).GetProperty("Text"), "D3"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlTextNode, "E1"); Assert.AreEqual(((XamlTextNode)n).TextContent, "Hello", "E2"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "F1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "F2"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode, "F3"); } @@@ -387,36 -387,36 +388,36 @@@ ""; XamlNode n; -- XamlParser p = new XamlParser(new StringReader(MAPPING + s)); ++ object p = buildParser(new StringReader(MAPPING + s)); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode); Assert.AreEqual(n.Depth, 0); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp)); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode); Assert.AreEqual(n.Depth, 1); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleWriter)); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlPropertyNode); Assert.AreEqual(((XamlPropertyNode)n).DP, ConsoleApp.RepetitionsProperty); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlTextNode); Assert.AreEqual(((XamlTextNode)n).TextContent, "3"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode); } @@@ -452,37 -452,37 +453,37 @@@ ""; XamlNode n; -- XamlParser p = new XamlParser(new StringReader(MAPPING + s)); ++ object p = buildParser(new StringReader(MAPPING + s)); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode); Assert.AreEqual(n.Depth, 0); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp)); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode); Assert.AreEqual(n.Depth, 1); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleWriter)); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlPropertyNode); Assert.AreEqual(n.Depth, 2); Assert.AreEqual(((XamlPropertyNode)n).DP, ConsoleApp.RepetitionsProperty); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlTextNode); Assert.AreEqual(((XamlTextNode)n).TextContent, "3"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode); } @@@ -508,44 -508,44 +509,44 @@@ "\n" + "\n" + ""; -- XamlParser p = new XamlParser(new StringReader(MAPPING + s)); ++ object p = buildParser(new StringReader(MAPPING + s)); XamlNode n; -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode, "A1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "B1"); Assert.AreEqual(n.Depth, 0, "B2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp), "B3"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "C1"); Assert.AreEqual(1, n.Depth, "C2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleReader), "C3"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlPropertyNode, "D1"); Assert.AreEqual(2, n.Depth, "D3"); Assert.AreEqual(((XamlPropertyNode)n).PropInfo, typeof(ConsoleReader).GetProperty("Prompt"), "D2"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "E1" + n.GetType()); Assert.AreEqual(3, n.Depth, "E2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleWriter), "E3"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "F1" + n.GetType()); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlPropertyComplexEndNode, "G1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "H1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "I1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode, "J1"); } @@@ -579,25 -579,25 +580,25 @@@ { string s = "\n"+ ""; -- XamlParser p = new XamlParser(new StringReader(MAPPING + s)); ++ object p = buildParser(new StringReader(MAPPING + s)); XamlNode n; -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode, "A1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "B1"); Assert.AreEqual(n.Depth, 0, "B2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp), "B3"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlClrEventNode, "C1"); Assert.AreEqual(((XamlClrEventNode)n).EventMember, typeof(ConsoleApp).GetEvent("SomethingHappened"), "C2"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "D1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode, "E1"); } @@@ -607,39 -607,39 +608,39 @@@ string s = "\n"+ "\n"+ ""; -- XamlParser p = new XamlParser(new StringReader(MAPPING + s)); ++ object p = buildParser(new StringReader(MAPPING + s)); XamlNode n; -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode, "A1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "B1"); Assert.AreEqual(n.Depth, 0, "B2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp), "B3"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "C1"); Assert.AreEqual(n.Depth, 1, "C2"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleWriter), "C3"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlPropertyNode, "D1"); Assert.AreEqual(n.Depth, 1, "D2"); Assert.AreEqual(((XamlPropertyNode)n).PropInfo, typeof(ConsoleWriter).GetProperty("Filter"), "D3"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlClrEventNode, "E1"); Assert.AreEqual((MemberInfo)((XamlClrEventNode)n).EventMember, typeof(ConsoleWriter).GetProperty("Filter"), "E2"); Assert.AreEqual(((XamlClrEventNode)n).Value, "filterfilter", "E3"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "F1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "G1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode, "H1"); } @@@ -649,24 -649,24 +650,24 @@@ string s = "\n"+ " here there everywhere]]>\n"+ ""; -- XamlParser p = new XamlParser(new StringReader(MAPPING + s)); ++ object p = buildParser(new StringReader(MAPPING + s)); XamlNode n; -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentStartNode, "A1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementStartNode, "B1"); Assert.AreEqual(((XamlElementStartNode)n).ElementType, typeof(ConsoleApp), "B3"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlLiteralContentNode, "C1"); Assert.AreEqual("Hi there here there everywhere", ((XamlLiteralContentNode)n).Content, "C2"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlElementEndNode, "D1"); -- n = p.GetNextNode(); ++ n = getNextNode(p); Assert.IsTrue(n is XamlDocumentEndNode, "E1"); } @@@ -682,351 -682,351 +683,30 @@@ makeGoBang(MAPPING + s); } --} -- -- -- --abstract class Happening { -- // this space deliberately left blank --} -- --class CreateTopLevelHappening : Happening --{ -- public Type parent; -- public string className; -- public CreateTopLevelHappening(Type parent, string name) { -- this.parent = parent; -- this.className = name; -- } --} -- --class CreateObjectHappening : Happening --{ -- public Type type; -- public string objectName; -- public CreateObjectHappening(Type type, string name) { -- this.type = type; -- this.objectName = name; -- } --} -- --class CreateObjectTextHappening : Happening --{ -- public string text; -- public CreateObjectTextHappening(string text) { -- this.text = text; -- } --} -- --class EndObjectHappening : Happening --{ -- // this space deliberately left blank --} -- --class CreatePropertyHappening : Happening --{ -- public PropertyInfo property; -- public CreatePropertyHappening(PropertyInfo property){ -- this.property = property; -- } --} -- --class CreatePropertyTextHappening : Happening --{ -- public string text; -- public Type propertyType; -- public CreatePropertyTextHappening(string text, Type propertyType){ -- this.text = text; -- this.propertyType = propertyType; -- } --} -- --class CreatePropertyObjectHappening : Happening --{ -- public Type type; -- public string objectName; -- -- public CreatePropertyObjectHappening(Type type, string objectName) { -- this.type = type; -- this.objectName = objectName; -- } --} --class EndPropertyObjectHappening : Happening --{ -- public Type type; -- -- public EndPropertyObjectHappening(Type type) { -- this.type = type; -- } --} --class CreatePropertyDelegateHappening : Happening --{ -- public string functionName; -- public Type propertyType; -- -- public CreatePropertyDelegateHappening(string functionName, Type propertyType) { -- this.functionName = functionName; -- this.propertyType = propertyType; -- } --} -- --class EndPropertyHappening : Happening --{ -- // this space deliberately left blank --} -- --class CreateEventHappening : Happening --{ -- public EventInfo evt; -- public CreateEventHappening(EventInfo evt) { -- this.evt = evt; -- } --} -- --class CreateEventDelegateHappening : Happening --{ -- public string functionName; -- public Type eventDelegateType; -- public CreateEventDelegateHappening(string functionName, Type eventDelegateType) { -- this.functionName = functionName; -- this.eventDelegateType = eventDelegateType; -- } --} -- --class EndEventHappening : Happening --{ -- // this space deliberately left blank --} -- --class CreateDependencyPropertyHappening : Happening --{ -- public Type attachedTo; -- public string propertyName; -- public Type propertyType; -- public CreateDependencyPropertyHappening(Type attachedTo, string propertyName, Type propertyType) { -- this.attachedTo = attachedTo; -- this.propertyName = propertyName; -- this.propertyType = propertyType; -- } --} -- --class CreateDependencyPropertyTextHappening : Happening --{ -- public string text; -- public Type propertyType; -- public CreateDependencyPropertyTextHappening(string text, Type propertyType) { -- this.text = text; -- this.propertyType = propertyType; -- } --} -- --class EndDependencyPropertyHappening : Happening --{ -- // this space deliberately left blank --} -- --class CreateCodeHappening : Happening --{ -- public string code; -- public CreateCodeHappening(string code) { -- this.code = code; -- } --} -- --class FinishHappening : Happening --{ -- // this space deliberately left blank --} -- -- --class ParserTester : IXamlWriter { -- string document; -- Happening[] happenings; -- int c; -- public ParserTester(string document, params Happening[] happenings) -- { -- this.document = document; -- this.happenings = happenings; -- this.c = 0; -- } -- public void Test() -- { --/* XamlParser p = new XamlParser(new StringReader(document), -- this); -- p.Parse(); -- // if this fails, then we haven't consumed all the happenings -- Assert.AreEqual(happenings.Length, c);*/ -- Assert.IsTrue(false); -- } -- Happening getHappening() ++ XamlNode getNextNode(object p) { -- Assert.IsFalse(c >= happenings.Length, "not enough happenings in list"); -- return happenings[c++]; ++ MethodInfo getter = p.GetType().GetMethod("GetNextNode"); ++ Assert.IsTrue(getter != null, "Couldn't get next-node-getter"); ++ try { ++ XamlNode n = (XamlNode)getter.Invoke(p, null); ++ Assert.IsTrue(n != null, "Couldn't get next node"); ++ return n; ++ } catch (TargetInvocationException ex) { ++ throw ex.InnerException; ++ } } -- private void AssertSubclass(Type parent, bool consume) -- { -- Assert.IsFalse(c >= happenings.Length, "not enough happenings in list"); -- Happening child = happenings[c]; -- -- Debug.WriteLine("WRITER CURRENT EXPECTED THING: " + child.GetType()); --// -- if (child.GetType() != parent) -- Assert.Fail("The method called was a " + parent + ", but was expecting a " + child.GetType()); -- if (consume) -- c++; -- } -- private void d(string step) ++ object buildParser(TextReader input) { -- Debug.WriteLine("WRITER IN STEP" + step); ++ Type xamlParserType = (Type)typeof(Mono.Windows.Serialization.CodeWriter).GetField("xamlParserType", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); ++ Assert.IsTrue(xamlParserType != null, "couldn't get type of parser"); ++ object p = Activator.CreateInstance(xamlParserType, new object[] { input}); ++ Assert.IsTrue(p != null, "couldn't get instance of parser"); ++ return p; } -- -- public void CreateTopLevel(Type parent, string className) -- { -- d("CreateTopLevel"); -- AssertSubclass(typeof(CreateTopLevelHappening), false); -- -- CreateTopLevelHappening h = (CreateTopLevelHappening)getHappening(); -- Assert.AreEqual(h.parent, parent); -- Assert.AreEqual(h.className, className); -- } -- -- public void CreateObject(Type type, string objectName){ -- d("CreateObject"); -- AssertSubclass(typeof(CreateObjectHappening), false); -- -- CreateObjectHappening h = (CreateObjectHappening)getHappening(); -- Assert.AreEqual(h.type, type); -- Assert.AreEqual(h.objectName, objectName); -- } -- -- public void CreateObjectText(string text){ -- d("CreateObjectText"); -- AssertSubclass(typeof(CreateObjectTextHappening), false); -- -- CreateObjectTextHappening h = (CreateObjectTextHappening)getHappening(); -- Assert.AreEqual(h.text, text); -- } -- -- public void EndObject(){ -- d("EndObject"); -- AssertSubclass(typeof(EndObjectHappening), true); -- } -- -- public void CreateProperty(PropertyInfo property){ -- d("CreateProperty"); -- AssertSubclass(typeof(CreatePropertyHappening), false); -- -- CreatePropertyHappening h = (CreatePropertyHappening)getHappening(); -- Assert.AreEqual(h.property, property); -- } -- -- public void CreatePropertyObject(Type type, string objectName){ -- d("CreatePropertyObject"); -- AssertSubclass(typeof(CreatePropertyObjectHappening), false); -- -- CreatePropertyObjectHappening h = (CreatePropertyObjectHappening)getHappening(); -- Assert.AreEqual(h.type, type); -- Assert.AreEqual(h.objectName, objectName); -- } -- public void EndPropertyObject(Type type) { -- d("EndPropertyObject"); -- AssertSubclass(typeof(EndPropertyObjectHappening), false); -- -- EndPropertyObjectHappening h = (EndPropertyObjectHappening)getHappening(); -- Assert.AreEqual(h.type, type); -- } -- -- public void CreatePropertyText(string text, Type propertyType){ -- d("CreatePropertyText"); -- AssertSubclass(typeof(CreatePropertyTextHappening), false); -- -- CreatePropertyTextHappening h = (CreatePropertyTextHappening)getHappening(); -- Assert.AreEqual(h.text, text); -- Assert.AreEqual(h.propertyType, propertyType); -- } -- -- public void CreatePropertyDelegate(string functionName, Type propertyType){ -- d("CreatePropertyDelegate"); -- AssertSubclass(typeof(CreatePropertyDelegateHappening), false); -- -- CreatePropertyDelegateHappening h = (CreatePropertyDelegateHappening)getHappening(); -- Assert.AreEqual(h.functionName, functionName); -- Assert.AreEqual(h.propertyType, propertyType); -- } -- -- public void EndProperty(){ -- d("EndProperty"); -- AssertSubclass(typeof(EndPropertyHappening), true); -- } -- -- -- public void CreateEvent(EventInfo evt){ -- d("CreateEvent"); -- AssertSubclass(typeof(CreateEventHappening), false); -- -- CreateEventHappening h = (CreateEventHappening)getHappening(); -- Assert.AreEqual(h.evt, evt); -- } -- -- public void CreateEventDelegate(string functionName, Type eventDelegateType){ -- d("CreateEventDelegate"); -- AssertSubclass(typeof(CreateEventDelegateHappening), false); -- -- CreateEventDelegateHappening h = (CreateEventDelegateHappening)getHappening(); -- Assert.AreEqual(h.functionName, functionName); -- Assert.AreEqual(h.eventDelegateType, eventDelegateType); -- } -- -- public void EndEvent(){ -- d("EndEvent"); -- AssertSubclass(typeof(EndEventHappening), true); -- } -- -- -- public void CreateDependencyProperty(Type attachedTo, string propertyName, Type propertyType){ -- d("CreateDependencyProperty"); -- AssertSubclass(typeof(CreateDependencyPropertyHappening), false); -- -- CreateDependencyPropertyHappening h = (CreateDependencyPropertyHappening)getHappening(); -- Assert.AreEqual(h.attachedTo, attachedTo); -- Assert.AreEqual(h.propertyName, propertyName); -- Assert.AreEqual(h.propertyType, propertyType); -- } -- -- public void CreateDependencyPropertyText(string text, Type propertyType){ -- d("CreateDependencyPropertyText"); -- AssertSubclass(typeof(CreateDependencyPropertyTextHappening), false); -- -- CreateDependencyPropertyTextHappening h = (CreateDependencyPropertyTextHappening)getHappening(); -- Assert.AreEqual(h.text, text); -- Assert.AreEqual(h.propertyType, propertyType); -- } -- -- public void EndDependencyProperty(){ -- d("EndDependencyProperty"); -- AssertSubclass(typeof(EndDependencyPropertyHappening), true); -- } -- -- -- public void CreateCode(string code){ -- d("CreateCode"); -- AssertSubclass(typeof(CreateCodeHappening), false); -- -- CreateCodeHappening h = (CreateCodeHappening)getHappening(); -- Assert.AreEqual(h.code, code); -- } -- -- -- public void Finish() -- { -- d("Finish"); -- AssertSubclass(typeof(FinishHappening), true); -- } -- -- } ++ } diff --combined mcs/tools/xamlc/ChangeLog index c7c1823b8bd,c7c1823b8bd..5d60c92a12e --- a/mcs/tools/xamlc/ChangeLog +++ b/mcs/tools/xamlc/ChangeLog @@@ -1,3 -1,3 +1,8 @@@ ++2005-08-26 Iain McCoy ++ ++ * demo/runtimetest.cs: use the newly-renamed Parser class instead of ++ the interim ObjectWriter ++ 2005-08-23 Iain McCoy * xamlc.cs: consume the new CodeWriter interface diff --combined mcs/tools/xamlc/demo/runtimetest.cs index fc310b6e712,fc310b6e712..e8c20e16a06 --- a/mcs/tools/xamlc/demo/runtimetest.cs +++ b/mcs/tools/xamlc/demo/runtimetest.cs @@@ -1,11 -1,11 +1,10 @@@ using Xaml.TestVocab.Console; using System.Xml; using System.Windows.Serialization; --using Mono.Windows.Serialization; class RuntimeTest { public static void Main(string[] args) { -- ConsoleApp c = (ConsoleApp)ObjectWriter.Parse(new XmlTextReader("runtimetest.xaml")); ++ ConsoleApp c = (ConsoleApp)Parser.LoadXml(new XmlTextReader("runtimetest.xaml")); c.Run(); }