Author: iainmc
Date: 2005-07-05 23:57:07 -0400 (Tue, 05 Jul 2005)
New Revision: 46984
Added:
trunk/mcs/class/PresentationFramework/System.Windows.Serialization/Mapper.cs
trunk/mcs/class/PresentationFramework/System.Windows.Serialization/NamespaceMapEntry.cs
Removed:
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/Mapping.cs
Modified:
trunk/mcs/class/PresentationFramework/ChangeLog
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
trunk/mcs/class/PresentationFramework/PresentationFramework.dll.sources
Log:
2005-07-06 Iain McCoy <[EMAIL PROTECTED]>
* Mono.Windows.Serialization/Mapping.cs: removed in favour of
System.Windows.Serialization/Mapper.cs
* System.Windows.Serialization/Mapper.cs: Added because it is
the
microsoft-documented mapping API
* Mono.Windows.Serialization/XamlParser.cs: transition to the
new
mapper system, also some general converging on the name
DependencyProperty throughout instead of ContextProperty or
AttachedProperty.
Modified: trunk/mcs/class/PresentationFramework/ChangeLog
===================================================================
--- trunk/mcs/class/PresentationFramework/ChangeLog 2005-07-06 01:34:38 UTC
(rev 46983)
+++ trunk/mcs/class/PresentationFramework/ChangeLog 2005-07-06 03:57:07 UTC
(rev 46984)
@@ -1,3 +1,14 @@
+2005-07-06 Iain McCoy <[EMAIL PROTECTED]>
+
+ * Mono.Windows.Serialization/Mapping.cs: removed in favour of
+ System.Windows.Serialization/Mapper.cs
+ * System.Windows.Serialization/Mapper.cs: Added because it is the
+ microsoft-documented mapping API
+ * Mono.Windows.Serialization/XamlParser.cs: transition to the new
+ mapper system, also some general converging on the name
+ DependencyProperty throughout instead of ContextProperty or
+ AttachedProperty.
+
2005-07-05 Iain McCoy <[EMAIL PROTECTED]>
* Mono.Windows.Serialization/XamlParser.cs,
Modified:
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
===================================================================
---
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
2005-07-06 01:34:38 UTC (rev 46983)
+++
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
2005-07-06 03:57:07 UTC (rev 46984)
@@ -127,9 +127,11 @@
}
// top of stack is a reference to an object
- // pushes the name of the instance to attach to, the name of
- // the property, and a reference to an object
- public void CreateAttachedProperty(Type attachedTo, string
propertyName, Type propertyType)
+ // pushes a reference to the expression that
+ // will set the property and a reference to
+ // the name of the temp variable to hold the
+ // property
+ public void CreateDependencyProperty(Type attachedTo, string
propertyName, Type propertyType)
{
string varName = "temp";
varName += tempIndex;
@@ -149,7 +151,7 @@
}
// pops 2 items: the name of the property, and the object to
attach to
- public void EndAttachedProperty()
+ public void EndDependencyProperty()
{
objects.RemoveAt(objects.Count - 1);
CodeExpression call =
(CodeExpression)(objects[objects.Count - 1]);
@@ -198,10 +200,10 @@
// top of stack is reference to a property
public void CreatePropertyText(string text, Type propertyType,
Type converterType)
{
- CreateAttachedPropertyText(text, propertyType,
converterType);
+ CreateDependencyPropertyText(text, propertyType,
converterType);
}
// top of stack is reference to an attached property
- public void CreateAttachedPropertyText(string text, Type
propertyType, Type converterType)
+ public void CreateDependencyPropertyText(string text, Type
propertyType, Type converterType)
{
CodeExpression expr = new CodePrimitiveExpression(text);
if (converterType != null) {
Deleted:
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/Mapping.cs
===================================================================
--- trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/Mapping.cs
2005-07-06 01:34:38 UTC (rev 46983)
+++ trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/Mapping.cs
2005-07-06 03:57:07 UTC (rev 46984)
@@ -1,130 +0,0 @@
-//
-// Mapping.cs
-//
-// Author:
-// Iain McCoy ([EMAIL PROTECTED])
-//
-// (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 Type 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 Type 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;
- }
- }
- }
-}
Modified:
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
===================================================================
---
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
2005-07-06 01:34:38 UTC (rev 46983)
+++
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
2005-07-06 03:57:07 UTC (rev 46984)
@@ -33,17 +33,18 @@
using System.Xml;
using System.Reflection;
using System.Windows;
+using System.Windows.Serialization;
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 Mapper mapper = new Mapper(new string[] { });
private XmlReader reader;
private XamlWriter writer;
private enum CurrentType { Object,
Property,
- AttachedProperty,
+ DependencyProperty,
Code }
private class ParserState {
@@ -101,8 +102,7 @@
{
if (reader.Name != "Mapping")
Console.WriteLine("Unknown processing
instruction");
- Mapping mapping = new Mapping(reader.Value);
- mapper.AddMapping(mapping);
+ mapper.AddMappingProcessingInstruction(reader.Value);
}
void parseElement()
@@ -133,7 +133,7 @@
if (isNameOfAncestorClass(beforeDot,
(Type)currentState.obj))
parseNormalPropertyElement(afterDot);
else
- parseAttachedPropertyElement(beforeDot,
afterDot);
+ parseDependencyPropertyElement(beforeDot,
afterDot);
}
// check if the given name is the name of an ancestor of
@@ -162,9 +162,9 @@
{
if (currentState.type == CurrentType.Object) {
writer.CreateElementText(reader.Value);
- } else if (currentState.type ==
CurrentType.AttachedProperty) {
+ } else if (currentState.type ==
CurrentType.DependencyProperty) {
DependencyProperty dp =
(DependencyProperty)currentState.obj;
- writer.CreateAttachedPropertyText(reader.Value,
dp.PropertyType,
+
writer.CreateDependencyPropertyText(reader.Value, dp.PropertyType,
getTypeConverter(dp.PropertyType));
} else {
PropertyInfo prop =
(PropertyInfo)currentState.obj;
@@ -224,7 +224,7 @@
}
- void parseAttachedPropertyElement(string attachedTo, string
propertyName)
+ void parseDependencyPropertyElement(string attachedTo, string
propertyName)
{
Type currentType = (Type)currentState.obj;
ensureDependencyObject(currentType);
@@ -234,9 +234,9 @@
oldStates.Add(currentState);
currentState = new ParserState();
currentState.obj = dp;
- currentState.type = CurrentType.AttachedProperty;
+ currentState.type = CurrentType.DependencyProperty;
- writer.CreateAttachedProperty(typeAttachedTo,
propertyName, dp.PropertyType);
+ writer.CreateDependencyProperty(typeAttachedTo,
propertyName, dp.PropertyType);
}
void parseObjectElement()
@@ -245,7 +245,7 @@
string objectName = null;
bool isEmpty = reader.IsEmptyElement;
- parent = mapper.Resolve(reader.NamespaceURI,
reader.Name);
+ parent = mapper.GetType(reader.NamespaceURI,
reader.Name);
objectName = reader.GetAttribute("Class",
XAML_NAMESPACE);
if
(parent.GetInterface("System.Windows.Serialization.IAddChild") == null)
{} //TODO: throw exception
@@ -264,7 +264,7 @@
if (reader.LocalName.IndexOf(".") < 0)
parseLocalPropertyAttribute();
else
- parseContextPropertyAttribute();
+
parseDependencyPropertyAttribute();
} while (reader.MoveToNextAttribute());
}
@@ -334,7 +334,7 @@
void ensureDependencyObject(Type currentType)
{
if
(!currentType.IsSubclassOf(typeof(System.Windows.DependencyObject)))
- throw new Exception("Attached
properties can only be set on "+
+ throw new Exception("Dependency
properties can only be set on "+
"DependencyObjects (not
" + currentType.Name + ")");
}
Type findTypeToAttachTo(string attachedTo, string propertyName)
@@ -360,7 +360,7 @@
return (DependencyProperty)propField.GetValue(null);
}
- void parseContextPropertyAttribute()
+ void parseDependencyPropertyAttribute()
{
int index = reader.LocalName.LastIndexOf('.');
string attachedTo = reader.LocalName.Substring(0,
index);
@@ -371,10 +371,10 @@
Type typeAttachedTo = findTypeToAttachTo(attachedTo,
propertyName);
DependencyProperty dp =
getDependencyProperty(typeAttachedTo, propertyName);
- writer.CreateAttachedProperty(typeAttachedTo,
propertyName, dp.PropertyType);
- writer.CreateAttachedPropertyText(reader.Value,
dp.PropertyType,
+ writer.CreateDependencyProperty(typeAttachedTo,
propertyName, dp.PropertyType);
+ writer.CreateDependencyPropertyText(reader.Value,
dp.PropertyType,
getTypeConverter(dp.PropertyType));
- writer.EndAttachedProperty();
+ writer.EndDependencyProperty();
}
void parseEndElement()
@@ -385,8 +385,8 @@
writer.EndObject();
else if (currentState.type == CurrentType.Property)
writer.EndProperty();
- else if (currentState.type ==
CurrentType.AttachedProperty)
- writer.EndAttachedProperty();
+ else if (currentState.type ==
CurrentType.DependencyProperty)
+ writer.EndDependencyProperty();
pop();
}
Modified:
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
===================================================================
---
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
2005-07-06 01:34:38 UTC (rev 46983)
+++
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
2005-07-06 03:57:07 UTC (rev 46984)
@@ -47,9 +47,9 @@
void CreateEventDelegate(string functionName, Type
eventDelegateType);
void EndEvent();
- void CreateAttachedProperty(Type attachedTo, string
propertyName, Type propertyType);
- void CreateAttachedPropertyText(string text, Type propertyType,
Type converterType);
- void EndAttachedProperty();
+ void CreateDependencyProperty(Type attachedTo, string
propertyName, Type propertyType);
+ void CreateDependencyPropertyText(string text, Type
propertyType, Type converterType);
+ void EndDependencyProperty();
void CreateCode(string code);
Modified:
trunk/mcs/class/PresentationFramework/PresentationFramework.dll.sources
===================================================================
--- trunk/mcs/class/PresentationFramework/PresentationFramework.dll.sources
2005-07-06 01:34:38 UTC (rev 46983)
+++ trunk/mcs/class/PresentationFramework/PresentationFramework.dll.sources
2005-07-06 03:57:07 UTC (rev 46984)
@@ -1,7 +1,8 @@
System.Windows.Serialization/IAddChild.cs
+System.Windows.Serialization/Mapper.cs
+System.Windows.Serialization/NamespaceMapEntry.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
Copied:
trunk/mcs/class/PresentationFramework/System.Windows.Serialization/Mapper.cs
(from rev 46932,
trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/Mapping.cs)
===================================================================
--- trunk/mcs/class/PresentationFramework/Mono.Windows.Serialization/Mapping.cs
2005-07-05 08:55:40 UTC (rev 46932)
+++
trunk/mcs/class/PresentationFramework/System.Windows.Serialization/Mapper.cs
2005-07-06 03:57:07 UTC (rev 46984)
@@ -0,0 +1,150 @@
+//
+// Mapper.cs
+//
+// Author:
+// Iain McCoy ([EMAIL PROTECTED])
+//
+// (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 System.Windows.Serialization {
+
+ class Mapper {
+ private ArrayList map = new ArrayList();
+ private ArrayList assemblyNames = new ArrayList();
+ private Hashtable assemblyPath = new Hashtable();
+
+ public Mapper(string[] assemblyNames)
+ {
+ foreach (string name in assemblyNames) {
+ this.assemblyNames.Add(name);
+ }
+ }
+ public Mapper(string[] assemblyNames, NamespaceMapEntry[] map)
: this(assemblyNames)
+ {
+ foreach (NamespaceMapEntry entry in map) {
+ this.map.Add(entry);
+ }
+ }
+
+ public void AddMappingProcessingInstruction(string
xmlNamespace, string clrNamespace, string assemblyName)
+ {
+ NamespaceMapEntry entry = new
NamespaceMapEntry(xmlNamespace, assemblyName, clrNamespace);
+ map.Add(entry);
+ }
+
+ // this function takes the processing instructions value, which
+ // should be something like:
+ // Assembly="Foo.dll" ClrNamespace="Foo" XmlNamespace="foo"
+ public void AddMappingProcessingInstruction(string instruction)
+ {
+ string xmlNamespace = null, clrNamespace = null,
assemblyName = null;
+ 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");
+ AddMappingProcessingInstruction(xmlNamespace,
clrNamespace, assemblyName);
+ }
+
+ public string[] GetAssemblyNames()
+ {
+ return (string[])assemblyNames.ToArray(typeof(string));
+ }
+ public NamespaceMapEntry[] GetNamespaceMap()
+ {
+ return
(NamespaceMapEntry[])map.ToArray(typeof(NamespaceMapEntry));
+ }
+
+ public Type GetType(string xmlNamespace, string localName)
+ {
+ foreach (NamespaceMapEntry entry in map)
+ {
+ Assembly assembly =
getAssembly(entry.AssemblyName);
+ Type type = assembly.GetType(entry.ClrNamespace
+ "." + localName);
+ if (type != null)
+ return type;
+ }
+ return null;
+ }
+
+ Assembly getAssembly(string name)
+ {
+ if (assemblyPath[name] != null)
+ name = (string)assemblyPath[name];
+ return Assembly.Load(name);
+ }
+
+ public void SetAssemblyPath(string assemblyName, string
assemblyPath)
+ {
+ this.assemblyPath[assemblyName] = assemblyPath;
+ }
+
+ public static Mapper DefaultMapper {
+ get { throw new NotImplementedException(); }
+ }
+ }
+}
Added:
trunk/mcs/class/PresentationFramework/System.Windows.Serialization/NamespaceMapEntry.cs
===================================================================
---
trunk/mcs/class/PresentationFramework/System.Windows.Serialization/NamespaceMapEntry.cs
2005-07-06 01:34:38 UTC (rev 46983)
+++
trunk/mcs/class/PresentationFramework/System.Windows.Serialization/NamespaceMapEntry.cs
2005-07-06 03:57:07 UTC (rev 46984)
@@ -0,0 +1,55 @@
+//
+// NamespaceMapEntry.cs
+//
+// Author:
+// Iain McCoy ([EMAIL PROTECTED])
+//
+// (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 class NamespaceMapEntry {
+ private string xmlNamespace, clrNamespace, assemblyName;
+ public NamespaceMapEntry() {
+ }
+
+ public NamespaceMapEntry(string xmlNamespace, string
assemblyName, string clrNamespace)
+ {
+ this.xmlNamespace = xmlNamespace;
+ this.clrNamespace = clrNamespace;
+ this.assemblyName = assemblyName;
+ }
+
+ public string XmlNamespace {
+ get { return xmlNamespace; }
+ set { xmlNamespace = value; }
+ }
+ public string ClrNamespace {
+ get { return clrNamespace; }
+ set { clrNamespace = value; }
+ }
+ public string AssemblyName {
+ get { return assemblyName; }
+ set { assemblyName = value; }
+ }
+ }
+}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches