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-14 06:35:58 +0400
committerIain McCoy <iainmc@mono-cvs.ximian.com>2005-07-14 06:35:58 +0400
commit532204c4337157aaf6b8bf97aee158e3e84db1d4 (patch)
treef059c8c907d0c3b450b393d71b96c4a0cd8e8c29 /mcs/class/PresentationFramework
parente149cbf0ecc932645c6e1dd30c7660513822b624 (diff)
parent6f907686f05ee683c25a97da9692321fb0761178 (diff)
2005-07-14 Iain McCoy <iain@mccoy.id.au>
* demo/test.xaml: added first test of complex objects as property values * demo/TestVocab/ConsoleReader.cs, demo/TestVocab/ConsoleVars.cs: more functionality that will provide uses for more complicated xaml code. * xamlc.cs: much more useful error reporting. * demo/TestVocab/ConsoleWriter.cs, demo/TestVocab/ConsoleValue.cs, demo/Makefile: Added ConsoleValue class to allow testing of more complicated property scenarios * demo/TestVocab/ConsoleVars.cs, demo/TestVocab/ConsoleReader.cs: classes to put in more complicated test * Mono.Windows.Serialization/XamlParser.cs, Mono.Windows.Serialization/XamlWriter.cs, Mono.Windows.Serialization/CodeWriter.cs: Initial support for creating complex objects as values of properties * Mono.Windows.Serialization/XamlParser.cs: fixed bug in the code detecting that the file's contents must be finished, where it forbade whitespace after the XAML code svn path=/trunk/mcs/; revision=47291
Diffstat (limited to 'mcs/class/PresentationFramework')
-rw-r--r--mcs/class/PresentationFramework/ChangeLog13
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs67
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs9
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs46
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs2
5 files changed, 128 insertions, 9 deletions
diff --git a/mcs/class/PresentationFramework/ChangeLog b/mcs/class/PresentationFramework/ChangeLog
index f456ff7d706..b439335ffe7 100644
--- a/mcs/class/PresentationFramework/ChangeLog
+++ b/mcs/class/PresentationFramework/ChangeLog
@@ -1,3 +1,16 @@
+2005-07-14 Iain McCoy <iain@mccoy.id.au>
+
+ * Mono.Windows.Serialization/XamlParser.cs,
+ Mono.Windows.Serialization/XamlWriter.cs,
+ Mono.Windows.Serialization/CodeWriter.cs: Initial support for
+ creating complex objects as values of properties
+
+2005-07-13 Iain McCoy <iain@mccoy.id.au>
+
+ * Mono.Windows.Serialization/XamlParser.cs: fixed bug in the code
+ detecting that the file's contents must be finished, where it forbade
+ whitespace after the XAML code
+
2005-07-11 Iain McCoy <iain@mccoy.id.au>
* Makefile,
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
index 5a39087f192..204e2cc94fe 100644
--- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
@@ -234,6 +234,7 @@ namespace Mono.Windows.Serialization {
"GetConverter"),
new CodeTypeOfExpression(propertyType));
}
+
// top of stack is reference to a property
public void CreatePropertyText(string text, Type propertyType)
{
@@ -257,6 +258,72 @@ namespace Mono.Windows.Serialization {
constructor.Statements.Add(assignment);
}
+
+ public void CreatePropertyObject(Type type, string varName)
+ {
+ bool isDefaultName;
+ if (varName == null) {
+ isDefaultName = true;
+ 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;
+ } else {
+ isDefaultName = false;
+ }
+
+ if (!nameClashes.ContainsKey(varName))
+ nameClashes[varName] = 0;
+ else {
+ nameClashes[varName] = 1 + (int)nameClashes[varName];
+ varName += (int)nameClashes[varName];
+ }
+
+
+ if (isDefaultName) {
+ CodeVariableDeclarationStatement declaration =
+ new CodeVariableDeclarationStatement(type,
+ varName,
+ new CodeObjectCreateExpression(type));
+ constructor.Statements.Add(declaration);
+ } else {
+ CodeMemberField declaration = new CodeMemberField(type, varName);
+ declaration.InitExpression = new CodeObjectCreateExpression(type);
+ this.type.Members.Add(declaration);
+ }
+ CodeVariableReferenceExpression varRef = new CodeVariableReferenceExpression(varName);
+
+ objects.Add(type);
+ objects.Add(varRef);
+
+ }
+
+ public void EndPropertyObject(Type sourceType)
+ {
+ CodeExpression varRef = (CodeExpression)objects[objects.Count - 1];
+ objects.RemoveAt(objects.Count - 1);
+ Type destType = (Type)objects[objects.Count - 1];
+ objects.RemoveAt(objects.Count - 1);
+
+
+ CodeExpression expr;
+ if (destType == sourceType)
+ expr = varRef;
+ else
+ expr = new CodeCastExpression(
+ new CodeTypeReference(destType),
+ new CodeMethodInvokeExpression(
+ fetchConverter(sourceType),
+ "ConvertTo",
+ varRef,
+ new CodeTypeOfExpression(destType)));
+ CodeAssignStatement assignment = new CodeAssignStatement(
+ (CodeExpression)objects[objects.Count - 1],
+ expr);
+ constructor.Statements.Add(assignment);
+
+ }
public void EndObject()
{
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs
index e4a13f8a56f..f024812150b 100644
--- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/ObjectWriter.cs
@@ -103,6 +103,15 @@ namespace Mono.Windows.Serialization {
p.SetValue(o, text, null);
}
+ public void CreatePropertyObject(Type type, string name)
+ {
+ throw new NotImplementedException();
+ }
+ public void EndPropertyObject(Type sourceType)
+ {
+ throw new NotImplementedException();
+ }
+
// top of stack is reference to an attached property
public void CreateDependencyPropertyText(string text, Type propertyType)
{
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
index 39bdcf45349..10524cfdcb2 100644
--- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
@@ -76,7 +76,7 @@ namespace Mono.Windows.Serialization {
public void Parse()
{
while (reader.Read()) {
- if (begun && currentState == null)
+ if (begun && currentState == null && reader.NodeType != XmlNodeType.Whitespace)
throw new Exception("Too far: " + reader.NodeType + ", " + reader.Name);
if (currentState != null && currentState.type == CurrentType.Code)
{
@@ -103,7 +103,8 @@ namespace Mono.Windows.Serialization {
parseText();
break;
case XmlNodeType.Whitespace:
- // skip whitespace
+ case XmlNodeType.Comment:
+ // skip whitespace and comments
break;
default:
Console.Out.WriteLine("Unknown element type " + reader.NodeType);
@@ -244,7 +245,13 @@ namespace Mono.Windows.Serialization {
string name = reader.GetAttribute("Name", XAML_NAMESPACE);
if (name == null)
name = reader.GetAttribute("Name", reader.NamespaceURI);
- addChild(parent, name);
+
+ if (currentState.type == CurrentType.Object)
+ addChild(parent, name);
+ else if (currentState.type == CurrentType.Property)
+ addPropertyChild(parent, name);
+ else
+ throw new NotImplementedException();
}
if (reader.MoveToFirstAttribute()) {
@@ -270,10 +277,11 @@ namespace Mono.Windows.Serialization {
void createTopLevel(string parentName, string className)
{
Type t = Type.GetType(parentName);
+
+ writer.CreateTopLevel(t, className);
currentState = new ParserState();
currentState.type = CurrentType.Object;
currentState.obj = t;
- writer.CreateTopLevel(t, className);
}
void addChild(Type type, string objectName)
@@ -284,6 +292,18 @@ namespace Mono.Windows.Serialization {
currentState.type = CurrentType.Object;
currentState.obj = type;
}
+
+ void addPropertyChild(Type type, string objectName)
+ {
+// writer.CreatePropertyObject(type, objectName);
+ writer.CreatePropertyObject(((PropertyInfo)currentState.obj).PropertyType, objectName);
+
+ oldStates.Add(currentState);
+ currentState = new ParserState();
+ currentState.type = CurrentType.Object;
+ currentState.obj = type;
+ }
+
void parseLocalPropertyAttribute()
@@ -367,14 +387,22 @@ namespace Mono.Windows.Serialization {
void parseEndElement()
{
- if (currentState.type == CurrentType.Code)
+ if (currentState.type == CurrentType.Code) {
writer.CreateCode((string)currentState.obj);
- else if (currentState.type == CurrentType.Object)
- writer.EndObject();
- else if (currentState.type == CurrentType.Property)
+ } else if (currentState.type == CurrentType.Object) {
+ ParserState prev = null;
+ if (oldStates.Count > 1)
+ prev = (ParserState)oldStates[oldStates.Count - 1];
+
+ if (prev != null && prev.type == CurrentType.Property)
+ writer.EndPropertyObject((Type)currentState.obj);
+ else
+ writer.EndObject();
+ } else if (currentState.type == CurrentType.Property) {
writer.EndProperty();
- else if (currentState.type == CurrentType.DependencyProperty)
+ } else if (currentState.type == CurrentType.DependencyProperty) {
writer.EndDependencyProperty();
+ }
pop();
}
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
index ba760e0b3de..5de3c224985 100644
--- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
@@ -40,6 +40,8 @@ namespace Mono.Windows.Serialization {
void CreateProperty(PropertyInfo property);
void CreatePropertyText(string text, Type propertyType);
void CreatePropertyDelegate(string functionName, Type propertyType);
+ void CreatePropertyObject(Type destType, string name);
+ void EndPropertyObject(Type sourceType);
void EndProperty();