Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIain McCoy <iainmc@mono-cvs.ximian.com>2005-07-02 13:28:36 +0400
committerIain McCoy <iainmc@mono-cvs.ximian.com>2005-07-02 13:28:36 +0400
commit83f1d3436e10afcb175187270817bdd93f5e4569 (patch)
treeef321ff2ad6b4481f6bcde7b0f06d7d4fe060bdb /mcs/class/PresentationFramework
parent1778a666aeab87bc6b2bfdc7132df6dfe500da40 (diff)
2005-07-02 Iain McCoy <iain@mccoy.id.au>
* tools/xamlc: initial in-progress version of xaml compiler and example * class/PresentationFramework: xaml support code * class/WindowsBase: initial version of DependencyObject, mostly for DependencyProperty support svn path=/trunk/mcs/; revision=46873
Diffstat (limited to 'mcs/class/PresentationFramework')
-rw-r--r--mcs/class/PresentationFramework/Assembly/AssemblyInfo.cs39
-rw-r--r--mcs/class/PresentationFramework/ChangeLog3
-rw-r--r--mcs/class/PresentationFramework/Makefile9
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs135
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/Exceptions.cs42
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/Mapping.cs130
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs292
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs43
-rw-r--r--mcs/class/PresentationFramework/PresentationFramework.dll.sources7
-rw-r--r--mcs/class/PresentationFramework/System.Windows.Serialization/IAddChild.cs34
10 files changed, 734 insertions, 0 deletions
diff --git a/mcs/class/PresentationFramework/Assembly/AssemblyInfo.cs b/mcs/class/PresentationFramework/Assembly/AssemblyInfo.cs
new file mode 100644
index 00000000000..9feda362032
--- /dev/null
+++ b/mcs/class/PresentationFramework/Assembly/AssemblyInfo.cs
@@ -0,0 +1,39 @@
+//
+// AssemblyInfo.cs
+//
+// Author:
+// Iain McCoy (iain@mccoy.id.au)
+// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
+//
+// (C) 2003 Ximian, Inc. http://www.ximian.com
+// (C) 2004 Novell (http://www.novell.com)
+//
+// this file based on mcs/class/Mono.Data.SqlClient/Assembly/AssemblyInfo.cs
+
+using System;
+using System.Reflection;
+using System.Runtime.InteropServices;
+
+#if (NET_1_0)
+ [assembly: AssemblyVersion ("1.0.3300.0")]
+#elif (NET_2_0)
+ [assembly: AssemblyVersion ("2.0.3600.0")]
+#elif (NET_1_1)
+ [assembly: AssemblyVersion ("1.0.5000.0")]
+#endif
+
+/* TODO COMPLETE INFORMATION
+
+[assembly: AssemblyTitle ("")]
+[assembly: AssemblyDescription ("")]
+
+[assembly: CLSCompliant (true)]
+[assembly: AssemblyFileVersion ("0.0.0.1")]
+
+[assembly: ComVisible (false)]
+
+*/
+
+[assembly: AssemblyDelaySign (true)]
+[assembly: AssemblyKeyFile ("../mono.pub")]
+
diff --git a/mcs/class/PresentationFramework/ChangeLog b/mcs/class/PresentationFramework/ChangeLog
new file mode 100644
index 00000000000..d2e6b96d74d
--- /dev/null
+++ b/mcs/class/PresentationFramework/ChangeLog
@@ -0,0 +1,3 @@
+2005-07-02 Iain McCoy <iain@mccoy.id.au>
+
+ * whole folder: implementation of Xaml-related namespaces
diff --git a/mcs/class/PresentationFramework/Makefile b/mcs/class/PresentationFramework/Makefile
new file mode 100644
index 00000000000..c7011cf42ec
--- /dev/null
+++ b/mcs/class/PresentationFramework/Makefile
@@ -0,0 +1,9 @@
+thisdir = class/PresentationFramework
+include ../../build/rules.make
+
+LIBRARY = PresentationFramework.dll
+
+LIB_MCS_FLAGS = -r:System.Xml.dll -r:WindowsBase.dll
+NO_TEST = yes
+
+include ../../build/library.make
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
new file mode 100644
index 00000000000..1258074f474
--- /dev/null
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
@@ -0,0 +1,135 @@
+//
+// 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.IO;
+using System.Collections;
+
+namespace Mono.Windows.Serialization {
+ public class CodeWriter : XamlWriter {
+ TextWriter writer;
+ ArrayList objects = new ArrayList();
+ Hashtable nameClashes = new Hashtable();
+ int tempIndex = 0;
+
+ public CodeWriter(TextWriter writer)
+ {
+ this.writer = writer;
+ }
+
+ public void CreateTopLevel(string parentName, string className)
+ {
+ Type parent = Type.GetType(parentName);
+ writer.WriteLine(className + " extends " +
+ parent.Namespace + "." + parent.Name);
+ objects.Add("this");
+ }
+
+ public void CreateObject(string typeName)
+ {
+ Type type = Type.GetType(typeName);
+ string varName = Char.ToLower(type.Name[0]) + type.Name.Substring(1);
+ // make sure something sensible happens when class
+ // names start with a lowercase letter
+ if (varName == type.Name)
+ varName = "_" + varName;
+
+ if (!nameClashes.ContainsKey(varName))
+ nameClashes[varName] = 0;
+ else {
+ nameClashes[varName] = 1 + (int)nameClashes[varName];
+ varName += (int)nameClashes[varName];
+ }
+
+ writer.WriteLine(type.Name + " " + varName);
+ writer.WriteLine(objects[objects.Count - 1] + ".AddChild(" + varName + ")");
+ objects.Add(varName);
+ }
+
+ public void CreateProperty(string propertyName)
+ {
+ string varName = (string)objects[objects.Count - 1];
+ string prop = varName + "." + propertyName;
+ objects.Add(prop);
+ }
+
+ public void CreateAttachedProperty(string attachedTo, string propertyName, string typeName)
+ {
+ Type t = Type.GetType(typeName);
+ objects.Add(attachedTo);
+ objects.Add(propertyName);
+
+ string name = "temp";
+ if (tempIndex != 0)
+ name += tempIndex;
+ writer.WriteLine(t.Name + " " + name);
+ objects.Add(name);
+ }
+
+ public void EndAttachedProperty()
+ {
+ string varName = (string)(objects[objects.Count - 1]);
+ string propertyName = (string)(objects[objects.Count - 2]);
+ string attachedTo = (string)(objects[objects.Count - 3]);
+ objects.RemoveAt(objects.Count - 1);
+ objects.RemoveAt(objects.Count - 1);
+ objects.RemoveAt(objects.Count - 1);
+ writer.WriteLine(attachedTo + ".Set" + propertyName + "(" + objects[objects.Count - 1] + ", " + varName + ");");
+ }
+
+ public void CreateElementText(string text)
+ {
+ writer.WriteLine(objects[objects.Count - 1] + ".AddText(\"" + text +"\")");
+ }
+
+ public void CreatePropertyText(string text)
+ {
+ writer.WriteLine(objects[objects.Count - 1] + " = " +
+ "\"" + text + "\"");
+ }
+ public void CreateAttachedPropertyText(string text)
+ {
+ writer.WriteLine(objects[objects.Count - 1] + " = " + text);
+ }
+
+ public void EndObject()
+ {
+ objects.RemoveAt(objects.Count - 1);
+ }
+
+ public void EndProperty()
+ {
+ objects.RemoveAt(objects.Count - 1);
+ }
+
+ public void Finish()
+ {
+ writer.Close();
+ }
+ }
+}
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/Exceptions.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/Exceptions.cs
new file mode 100644
index 00000000000..ae0b58861c0
--- /dev/null
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/Exceptions.cs
@@ -0,0 +1,42 @@
+//
+// Exceptions.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;
+
+namespace Mono.Windows.Serialization {
+ public class MappingException : Exception {
+ public MappingException(string ClassName, string XmlNamespace) : base(ClassName + " was not found in " + XmlNamespace)
+ {}
+ }
+
+ public class MapParsingException : Exception {
+ public MapParsingException(string error) : base(error)
+ {}
+ }
+}
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/Mapping.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/Mapping.cs
new file mode 100644
index 00000000000..07d9d6eb02b
--- /dev/null
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/Mapping.cs
@@ -0,0 +1,130 @@
+//
+// Mapping.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.Collections;
+
+namespace Mono.Windows.Serialization {
+
+ class Mapper {
+ private Hashtable mappings = new Hashtable();
+ public void AddMapping(Mapping mapping)
+ {
+ if (mappings.ContainsKey(mapping.XmlNamespace))
+ {}// TODO: throw exception
+
+ mappings[mapping.XmlNamespace] = mapping;
+ }
+
+ public string Resolve(string clrNamespace, string classname)
+ {
+ return ((Mapping)mappings[clrNamespace]).Resolve(classname);
+ }
+ }
+
+ class Mapping {
+ string xmlNamespace;
+ string clrNamespace;
+ string assemblyName;
+
+ // this function takes the processing instructions value, which
+ // should be something like:
+ // Assembly="Foo.dll" ClrNamespace="Foo" XmlNamespace="foo"
+ public Mapping(string instruction)
+ {
+ string name = "", value = "";
+ int i = 0;
+ instruction = instruction.Trim();
+ while (i != instruction.Length) {
+ name = "";
+ value = "";
+ while (Char.IsWhiteSpace(instruction[i]))
+ i++;
+ while (instruction[i] != '=') {
+ name += instruction[i];
+ i++;
+ }
+ i++; // go past the = sign
+ if (instruction[i] == '"')
+ i++; // go past the "
+ //TODO: else and exception
+ while (instruction[i] != '"') {
+ value += instruction[i];
+ i++;
+ }
+ if (instruction[i] == '"')
+ i++; // go past another "
+
+ switch(name) {
+ case "ClrNamespace":
+ if (clrNamespace == null)
+ clrNamespace = value;
+ // TODO: else and exception
+ break;
+ case "Assembly":
+ if (assemblyName == null)
+ assemblyName = value;
+ // TODO: else and exception
+ break;
+ case "XmlNamespace":
+ if (xmlNamespace == null)
+ xmlNamespace = value;
+ // TODO: else and exception
+ break;
+ }
+ }
+ if (clrNamespace == null ||
+ assemblyName == null ||
+ xmlNamespace == null)
+ throw new Exception("underspecified");
+ }
+
+ public Mapping(string clrNamespace, string assembly, string xmlNamespace)
+ {
+ this.clrNamespace = clrNamespace;
+ this.assemblyName = assembly;
+ this.xmlNamespace = xmlNamespace;
+ }
+
+ public string XmlNamespace {
+ get { return xmlNamespace; }
+ }
+
+ public string Resolve(string className)
+ {
+ Assembly assembly = Assembly.Load(assemblyName);
+ Type type = assembly.GetType(clrNamespace + "." + className);
+ if (type == null) {
+ throw new MappingException(className, XmlNamespace);
+ } else {
+ return type.AssemblyQualifiedName;
+ }
+ }
+ }
+}
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
new file mode 100644
index 00000000000..fd4d8220114
--- /dev/null
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
@@ -0,0 +1,292 @@
+//
+// XamlParser.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.Collections;
+using System.IO;
+using System.Xml;
+using System.Reflection;
+using System.Windows;
+
+namespace Mono.Windows.Serialization {
+ public class XamlParser {
+ public const string XAML_NAMESPACE = "http://schemas.microsoft.com/winfx/xaml/2005";
+ private Mapper mapper = new Mapper();
+ private XmlReader reader;
+ private XamlWriter writer;
+
+ private enum CurrentType { Object, Property, AttachedProperty }
+
+ private class ParserState {
+ public object obj;
+ public CurrentType type;
+ }
+
+ private ParserState currentState = null;
+ private ArrayList oldStates = new ArrayList();
+
+ public XamlParser(string filename, XamlWriter writer)
+ {
+ reader = new XmlTextReader(filename);
+ this.writer = writer;
+ }
+
+ public void Parse()
+ {
+ while (reader.Read()) {
+ switch (reader.NodeType) {
+ case XmlNodeType.ProcessingInstruction:
+ parsePI();
+ break;
+ case XmlNodeType.Element:
+ parseElement();
+ break;
+ case XmlNodeType.EndElement:
+ parseEndElement();
+ break;
+ case XmlNodeType.Text:
+ parseText();
+ break;
+ case XmlNodeType.Whitespace:
+ // skip whitespace
+ break;
+ default:
+ Console.Out.WriteLine("Unknown element type " + reader.NodeType);
+ break;
+ }
+ }
+ }
+ void parsePI()
+ {
+ if (reader.Name != "Mapping")
+ Console.WriteLine("Unknown processing instruction");
+ Mapping mapping = new Mapping(reader.Value);
+ mapper.AddMapping(mapping);
+ }
+
+ void parseElement()
+ {
+ // This element must be an object if:
+ // - It's a direct child of a property element
+ // - It's a direct child of an IAddChild element
+ // and does not have a dot in its name
+ //
+ // parseObjectElement will verify the second case
+ //
+ // If it's a dotted name, then it is a property.
+ // What it is a property of depends on the bit of the
+ // name before the dot.
+ int dotPosition = reader.LocalName.IndexOf('.');
+ if (dotPosition < 0 ||
+ currentState.type == CurrentType.Property) {
+ parseObjectElement();
+ return;
+ }
+ string beforeDot = reader.LocalName.Substring(0, dotPosition);
+ string afterDot = reader.LocalName.Substring(dotPosition + 1);
+ // If we've got this far, then currentState.Type == Object
+ if (isNameOfAncestorClass(beforeDot, (Type)currentState.obj))
+ parseNormalPropertyElement(afterDot);
+ else
+ parseAttachedPropertyElement(beforeDot, afterDot);
+ }
+
+ // check if the given name is the name of an ancestor of
+ // the given type
+ bool isNameOfAncestorClass(string name, Type t)
+ {
+ while (t.BaseType != null) {
+ if (t.Name == name)
+ return true;
+ t = t.BaseType;
+ }
+ return false;
+ }
+
+ void parseText()
+ {
+ if (currentState.type == CurrentType.Object)
+ writer.CreateElementText(reader.Value);
+ else if (currentState.type == CurrentType.AttachedProperty)
+ writer.CreateAttachedPropertyText(reader.Value);
+ else
+ writer.CreatePropertyText(reader.Value);
+ }
+
+ void parseNormalPropertyElement(string propertyName)
+ {
+ // preconditions: currentState.Type == Object
+ Type currentType = (Type)currentState.obj;
+ PropertyInfo prop = currentType.GetProperty(propertyName);
+ if (prop == null) {
+ Console.WriteLine("Property " + propertyName + " not found on " + currentType.Name);
+ return;
+ // TODO: exception
+ }
+
+ ParserState newState = new ParserState();
+ newState.type = CurrentType.Property;
+ newState.obj = prop;
+ oldStates.Add(currentState);
+ currentState = newState;
+
+ writer.CreateProperty(propertyName);
+
+ if (reader.HasAttributes) {
+ Console.WriteLine("Property node should not have attributes");
+ return;
+ // TODO: exception
+ }
+ }
+
+ void parseAttachedPropertyElement(string attachedTo, string propertyName)
+ {
+ Type typeAttachedTo = null;
+ FieldInfo propField;
+ DependencyProperty dp;
+ Type currentType = (Type)currentState.obj;
+ if (!currentType.IsSubclassOf(typeof(System.Windows.DependencyObject)))
+ throw new Exception("Attached properties can only be set on DependencyObjects (not " + currentType.Name + ")");
+ foreach (ParserState state in oldStates) {
+ if (state.type == CurrentType.Object &&
+ ((Type)state.obj).Name == attachedTo) {
+ typeAttachedTo = (Type)state.obj;
+ break;
+ }
+ }
+ if (typeAttachedTo == null)
+ throw new Exception("Nothing to attach to: " + attachedTo + "." + propertyName);
+ propField = typeAttachedTo.GetField(propertyName + "Property");
+ if (propField == null)
+ throw new Exception("Property " + propertyName + " does not exist on " + attachedTo);
+ dp = (DependencyProperty)propField.GetValue(null);
+
+ oldStates.Add(currentState);
+ currentState = new ParserState();
+ currentState.obj = propField;
+ currentState.type = CurrentType.AttachedProperty;
+
+ writer.CreateAttachedProperty(attachedTo, propertyName, dp.PropertyType.AssemblyQualifiedName);
+ }
+
+ void parseObjectElement()
+ {
+ string parentName, objectName = null;
+ bool isEmpty = reader.IsEmptyElement;
+
+ parentName = mapper.Resolve(reader.NamespaceURI, reader.Name);
+ objectName = reader.GetAttribute("Class", XAML_NAMESPACE);
+ if (Type.GetType(parentName).GetInterface("System.Windows.Serialization.IAddChild") == null)
+ {} //TODO: throw exception
+ if (currentState == null) {
+ createTopLevel(parentName, objectName);
+ } else {
+ addChild(parentName);
+ }
+
+ if (reader.MoveToFirstAttribute()) {
+ do {
+ if (reader.LocalName.StartsWith("xmlns"))
+ continue;
+ if (reader.LocalName.IndexOf(".") < 0)
+ parseLocalPropertyAttribute();
+ else
+ parseContextPropertyAttribute();
+ } while (reader.MoveToNextAttribute());
+ }
+
+
+ if (isEmpty)
+ writer.EndObject();
+ }
+
+ void parseLocalPropertyAttribute()
+ {
+ string propertyName = reader.LocalName;
+ Type currentType = (Type)currentState.obj;
+ PropertyInfo prop = currentType.GetProperty(propertyName);
+ if (prop == null) {
+ Console.WriteLine("Property " + propertyName + " not found on " + currentType.Name);
+ return;
+ // TODO: throw exception
+ }
+
+ writer.CreateProperty(propertyName);
+ writer.CreatePropertyText(reader.Value);
+
+ parseEndElement();
+ }
+
+ void parseContextPropertyAttribute()
+ {
+ throw new NotImplementedException("parseContextPropertyAttribute");
+ }
+
+ void parseEndElement()
+ {
+ if (currentState.type == CurrentType.Object)
+ writer.EndObject();
+ else if (currentState.type == CurrentType.Property)
+ writer.EndProperty();
+ else if (currentState.type == CurrentType.AttachedProperty)
+ writer.EndAttachedProperty();
+
+
+ if (oldStates.Count == 0) {
+ currentState = null;
+ writer.Finish();
+ return;
+ }
+ int lastIndex = oldStates.Count - 1;
+ currentState = (ParserState)oldStates[lastIndex];
+ oldStates.RemoveAt(lastIndex);
+ }
+
+ void createTopLevel(string parentName, string objectName)
+ {
+ Type t = Type.GetType(parentName);
+ currentState = new ParserState();
+ currentState.type = CurrentType.Object;
+ currentState.obj = t;
+ if (objectName == null) {
+ objectName = "derived" + t.Name;
+ }
+ writer.CreateTopLevel(parentName, objectName);
+ }
+
+ void addChild(string className)
+ {
+ writer.CreateObject(className);
+ oldStates.Add(currentState);
+ currentState = new ParserState();
+ currentState.type = CurrentType.Object;
+ currentState.obj = Type.GetType(className);
+ }
+ }
+}
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
new file mode 100644
index 00000000000..238307af0c6
--- /dev/null
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
@@ -0,0 +1,43 @@
+//
+// XamlWriter.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.
+//
+
+namespace Mono.Windows.Serialization {
+ public interface XamlWriter {
+ void CreateTopLevel(string parentName, string className);
+ void CreateObject(string typeName);
+ void CreateProperty(string propertyName);
+ void CreateElementText(string text);
+ void CreatePropertyText(string text);
+ void CreateAttachedProperty(string attachedTo, string propertyName, string typeName);
+ void CreateAttachedPropertyText(string text);
+ void EndObject();
+ void EndProperty();
+ void EndAttachedProperty();
+ void Finish();
+ }
+}
diff --git a/mcs/class/PresentationFramework/PresentationFramework.dll.sources b/mcs/class/PresentationFramework/PresentationFramework.dll.sources
new file mode 100644
index 00000000000..3c5f13ec377
--- /dev/null
+++ b/mcs/class/PresentationFramework/PresentationFramework.dll.sources
@@ -0,0 +1,7 @@
+System.Windows.Serialization/IAddChild.cs
+Mono.Windows.Serialization/CodeWriter.cs
+Mono.Windows.Serialization/Exceptions.cs
+Mono.Windows.Serialization/Mapping.cs
+Mono.Windows.Serialization/XamlParser.cs
+Mono.Windows.Serialization/XamlWriter.cs
+Assembly/AssemblyInfo.cs
diff --git a/mcs/class/PresentationFramework/System.Windows.Serialization/IAddChild.cs b/mcs/class/PresentationFramework/System.Windows.Serialization/IAddChild.cs
new file mode 100644
index 00000000000..8423b8ce013
--- /dev/null
+++ b/mcs/class/PresentationFramework/System.Windows.Serialization/IAddChild.cs
@@ -0,0 +1,34 @@
+//
+// IAddChild.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.
+//
+
+namespace System.Windows.Serialization {
+ public interface IAddChild {
+ void AddChild(object value);
+ void AddText(string text);
+ }
+}