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-03 16:57:28 +0400
committerIain McCoy <iainmc@mono-cvs.ximian.com>2005-07-03 16:57:28 +0400
commitf1d124aa23fa928ff4e5b2ad8209b303a4523476 (patch)
tree4a93f378d1552e484ad18d40654fcd517d864990 /mcs/class/PresentationFramework
parent0b26d33a9b0e9697e3e138579325320754e1bafd (diff)
2005-07-03 Iain McCoy <iain@mccoy.id.au>
* demo/Makefile: made more useful - just do "make run" and it should all happen * demo/test.xaml: added Code section, which I think should make this thing a complete, if small, program * demo/TestVocab/*: some small bugfixes, with a little bit of craziness to work around the slightly bogus stuff in DependencyObject at the moment. * Mono.Windows.Serialization/XamlParser.cs: added support for Code elements, provide fully qualified name of type to attach to, skip xmns: attributes when processing, * Mono.Windows.Serialization/XamlWriter.cs: added WriteCode member, ordered methods by type of thing dealt with * Mono.Windows.Serialization/CodeWriter.cs: added support for Code elements, call empty constructor for objects, call TypeConverter almost correctly. svn path=/trunk/mcs/; revision=46889
Diffstat (limited to 'mcs/class/PresentationFramework')
-rw-r--r--mcs/class/PresentationFramework/ChangeLog11
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs26
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs50
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs12
4 files changed, 79 insertions, 20 deletions
diff --git a/mcs/class/PresentationFramework/ChangeLog b/mcs/class/PresentationFramework/ChangeLog
index b8ce3c41d22..32fee625ed5 100644
--- a/mcs/class/PresentationFramework/ChangeLog
+++ b/mcs/class/PresentationFramework/ChangeLog
@@ -1,5 +1,16 @@
2005-07-03 Iain McCoy <iain@mccoy.id.au>
+ * Mono.Windows.Serialization/XamlParser.cs: added support for Code
+ elements, provide fully qualified name of type to attach to, skip
+ xmns: attributes when processing,
+ * Mono.Windows.Serialization/XamlWriter.cs: added WriteCode member,
+ ordered methods by type of thing dealt with
+ * Mono.Windows.Serialization/CodeWriter.cs: added support for Code
+ elements, call empty constructor for objects, call TypeConverter
+ almost correctly.
+
+2005-07-03 Iain McCoy <iain@mccoy.id.au>
+
* Mono.Windows.Serialization/CodeWriter.cs: use CodeDom to do code
generation
* Mono.Windows.Serialization/CodeWriter.cs:
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
index 16cb2d0aa4a..7e2db10bc28 100644
--- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
@@ -40,6 +40,7 @@ namespace Mono.Windows.Serialization {
int tempIndex = 0;
CodeCompileUnit code;
+ CodeTypeDeclaration type;
CodeConstructor constructor;
// pushes: the code writer
@@ -65,7 +66,7 @@ namespace Mono.Windows.Serialization {
CodeNamespace ns = new CodeNamespace(clrNamespace);
((CodeCompileUnit)objects[0]).Namespaces.Add(ns);
- CodeTypeDeclaration type = new CodeTypeDeclaration(className);
+ type = new CodeTypeDeclaration(className);
type.BaseTypes.Add(new CodeTypeReference(parent));
constructor = new CodeConstructor();
type.Members.Add(constructor);
@@ -93,7 +94,9 @@ namespace Mono.Windows.Serialization {
}
CodeVariableDeclarationStatement declaration =
- new CodeVariableDeclarationStatement(type, varName);
+ new CodeVariableDeclarationStatement(type,
+ varName,
+ new CodeObjectCreateExpression(type));
CodeVariableReferenceExpression varRef = new CodeVariableReferenceExpression(varName);
CodeMethodInvokeExpression addChild = new CodeMethodInvokeExpression(
(CodeExpression)objects[objects.Count - 1],
@@ -119,8 +122,8 @@ namespace Mono.Windows.Serialization {
// the property, and a reference to an object
public void CreateAttachedProperty(string attachedTo, string propertyName, string typeName)
{
- // need to:
Type t = Type.GetType(typeName);
+ Type typeAttachedTo = Type.GetType(attachedTo);
string name = "temp";
if (tempIndex != 0)
@@ -130,7 +133,7 @@ namespace Mono.Windows.Serialization {
CodeMethodInvokeExpression call = new CodeMethodInvokeExpression(
- new CodeVariableReferenceExpression(attachedTo),
+ new CodeTypeReferenceExpression(typeAttachedTo),
"Set" + propertyName,
(CodeExpression)objects[objects.Count - 1],
new CodeVariableReferenceExpression(name));
@@ -169,10 +172,12 @@ namespace Mono.Windows.Serialization {
CodeExpression expr = new CodePrimitiveExpression(text);
if (converter != null) {
Type t = Type.GetType(converter);
- expr = new CodeMethodInvokeExpression(
- new CodeTypeReferenceExpression(t),
- "ConvertFromString",
- expr);
+ expr = new CodeCastExpression(
+ new CodeTypeReference(typeof(int)),
+ new CodeMethodInvokeExpression(
+ new CodeObjectCreateExpression(t),
+ "ConvertFromString",
+ expr));
}
CodeAssignStatement assignment = new CodeAssignStatement(
(CodeExpression)objects[objects.Count - 1],
@@ -197,5 +202,10 @@ namespace Mono.Windows.Serialization {
generator.GenerateCodeFromCompileUnit(code, writer, null);
writer.Close();
}
+
+ public void CreateCode(string code)
+ {
+ type.Members.Add(new CodeSnippetTypeMember(code));
+ }
}
}
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
index 6dbfdfaaa40..6939bcc8236 100644
--- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
@@ -41,7 +41,10 @@ namespace Mono.Windows.Serialization {
private XmlReader reader;
private XamlWriter writer;
- private enum CurrentType { Object, Property, AttachedProperty }
+ private enum CurrentType { Object,
+ Property,
+ AttachedProperty,
+ Code }
private class ParserState {
public object obj;
@@ -60,6 +63,18 @@ namespace Mono.Windows.Serialization {
public void Parse()
{
while (reader.Read()) {
+ if (currentState != null &&
+ currentState.type == CurrentType.Code)
+ {
+ if (reader.NodeType == XmlNodeType.EndElement &&
+ reader.LocalName == "Code" &&
+ reader.NamespaceURI == XAML_NAMESPACE) {
+ parseEndElement();
+ } else {
+ currentState.obj = (string)currentState.obj + reader.Value;
+ }
+ continue;
+ }
switch (reader.NodeType) {
case XmlNodeType.ProcessingInstruction:
parsePI();
@@ -92,6 +107,10 @@ namespace Mono.Windows.Serialization {
void parseElement()
{
+ if (reader.LocalName == "Code" && reader.NamespaceURI == XAML_NAMESPACE) {
+ parseCodeElement();
+ return;
+ }
// 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
@@ -129,6 +148,14 @@ namespace Mono.Windows.Serialization {
return false;
}
+ void parseCodeElement()
+ {
+ oldStates.Add(currentState);
+ currentState = new ParserState();
+ currentState.type = CurrentType.Code;
+ currentState.obj = "";
+ }
+
void parseText()
{
if (currentState.type == CurrentType.Object) {
@@ -160,7 +187,6 @@ namespace Mono.Windows.Serialization {
fromType.Name == "String")
return null;
string converterName = "System.ComponentModel." + fromType.Name + "Converter,System.dll";
- Console.WriteLine("YY '"+converterName + "'");
Type converter = assembly.GetType(converterName);
return converter.AssemblyQualifiedName;
// TODO: catch NullReferenceException and do something
@@ -179,11 +205,10 @@ namespace Mono.Windows.Serialization {
// TODO: exception
}
- ParserState newState = new ParserState();
- newState.type = CurrentType.Property;
- newState.obj = prop;
oldStates.Add(currentState);
- currentState = newState;
+ currentState = new ParserState();
+ currentState.type = CurrentType.Property;
+ currentState.obj = prop;
writer.CreateProperty(propertyName);
@@ -201,7 +226,8 @@ namespace Mono.Windows.Serialization {
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 + ")");
+ 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) {
@@ -221,7 +247,9 @@ namespace Mono.Windows.Serialization {
currentState.obj = dp;
currentState.type = CurrentType.AttachedProperty;
- writer.CreateAttachedProperty(attachedTo, propertyName, dp.PropertyType.AssemblyQualifiedName);
+ writer.CreateAttachedProperty(typeAttachedTo.AssemblyQualifiedName,
+ propertyName,
+ dp.PropertyType.AssemblyQualifiedName);
}
void parseObjectElement()
@@ -241,7 +269,9 @@ namespace Mono.Windows.Serialization {
if (reader.MoveToFirstAttribute()) {
do {
- if (reader.LocalName.StartsWith("xmlns"))
+ if (reader.Name.StartsWith("xmlns"))
+ continue;
+ if (reader.NamespaceURI == XAML_NAMESPACE)
continue;
if (reader.LocalName.IndexOf(".") < 0)
parseLocalPropertyAttribute();
@@ -280,6 +310,8 @@ namespace Mono.Windows.Serialization {
void parseEndElement()
{
+ if (currentState.type == CurrentType.Code)
+ writer.CreateCode((string)currentState.obj);
if (currentState.type == CurrentType.Object)
writer.EndObject();
else if (currentState.type == CurrentType.Property)
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
index b4365248c19..a4c956a4e8f 100644
--- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
@@ -29,15 +29,21 @@
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 EndObject();
+
+ void CreateProperty(string propertyName);
void CreatePropertyText(string text, string converter);
+ void EndProperty();
+
void CreateAttachedProperty(string attachedTo, string propertyName, string typeName);
void CreateAttachedPropertyText(string text, string converter);
- void EndObject();
- void EndProperty();
void EndAttachedProperty();
+
+ void CreateCode(string code);
+
void Finish();
}
}