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
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
-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
-rw-r--r--mcs/tools/xamlc/ChangeLog9
-rw-r--r--mcs/tools/xamlc/demo/Makefile11
-rw-r--r--mcs/tools/xamlc/demo/TestVocab/ConsoleApp.cs5
-rw-r--r--mcs/tools/xamlc/demo/TestVocab/ConsoleWriter.cs19
-rw-r--r--mcs/tools/xamlc/demo/test.xaml11
9 files changed, 126 insertions, 28 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();
}
}
diff --git a/mcs/tools/xamlc/ChangeLog b/mcs/tools/xamlc/ChangeLog
index 8f26c9818ce..c9f27bf066c 100644
--- a/mcs/tools/xamlc/ChangeLog
+++ b/mcs/tools/xamlc/ChangeLog
@@ -1,3 +1,12 @@
+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.
+
2005-07-02 Iain McCoy <iain@mccoy.id.au>
* whole folder: first emphatically work-in-progress version of xaml
diff --git a/mcs/tools/xamlc/demo/Makefile b/mcs/tools/xamlc/demo/Makefile
index cbd6f1e2f04..1b8d615487c 100644
--- a/mcs/tools/xamlc/demo/Makefile
+++ b/mcs/tools/xamlc/demo/Makefile
@@ -3,11 +3,14 @@ include ../../../build/rules.make
SOURCES=TestVocab/ConsoleApp.cs TestVocab/ConsoleWriter.cs TestVocab/IConsoleAction.cs
-all-local: TestVocab.dll test.xaml.out
+run:
+ make TestVocab.dll
+ MONO_PATH="." $(RUNTIME) --debug ../xamlc.exe -o:test.xaml.out.cs test.xaml
+ $(CSCOMPILE) -r:TestVocab.dll -o test.exe test.xaml.out.cs
+ $(RUNTIME) --debug test.exe
+
+all-local: TestVocab.dll
TestVocab.dll: $(SOURCES)
$(CSCOMPILE) -r:PresentationFramework.dll -r:WindowsBase.dll -out:TestVocab.dll -target:library $(SOURCES)
-test.xaml.out:
- make TestVocab.dll
- MONO_PATH="." $(RUNTIME) ../xamlc.exe -o:test.xaml.out test.xaml
diff --git a/mcs/tools/xamlc/demo/TestVocab/ConsoleApp.cs b/mcs/tools/xamlc/demo/TestVocab/ConsoleApp.cs
index 4212101385c..4d75d368d82 100644
--- a/mcs/tools/xamlc/demo/TestVocab/ConsoleApp.cs
+++ b/mcs/tools/xamlc/demo/TestVocab/ConsoleApp.cs
@@ -5,7 +5,7 @@ using System.Windows.Serialization;
namespace Xaml.TestVocab.Console {
public class ConsoleApp : IAddChild {
- private ArrayList actions;
+ private ArrayList actions = new ArrayList();
public void AddText(string Text)
{
actions.Add(new ConsoleWriter(Text));
@@ -36,7 +36,8 @@ namespace Xaml.TestVocab.Console {
}
public static int GetRepetitions(DependencyObject d)
{
- return (int)d.GetValue(RepetitionsProperty);
+ object v = d.GetValue(RepetitionsProperty);
+ return (v == null ? 1 : (int)v);
}
}
}
diff --git a/mcs/tools/xamlc/demo/TestVocab/ConsoleWriter.cs b/mcs/tools/xamlc/demo/TestVocab/ConsoleWriter.cs
index 0e9117592ab..e57a722ee4f 100644
--- a/mcs/tools/xamlc/demo/TestVocab/ConsoleWriter.cs
+++ b/mcs/tools/xamlc/demo/TestVocab/ConsoleWriter.cs
@@ -1,9 +1,16 @@
+using System;
using System.Windows;
+using System.Windows.Serialization;
namespace Xaml.TestVocab.Console {
- public class ConsoleWriter : DependencyObject {
+ public class ConsoleWriter : DependencyObject, IAddChild, IConsoleAction {
string text;
+ public ConsoleWriter()
+ {
+ text = "";
+ }
+
public ConsoleWriter(string text)
{
this.text = text;
@@ -14,6 +21,16 @@ namespace Xaml.TestVocab.Console {
set { text = value; }
}
+ public void AddText(string text)
+ {
+ this.text += text;
+ }
+
+ public void AddChild(Object o)
+ {
+ throw new NotImplementedException();
+ }
+
public void Run()
{
diff --git a/mcs/tools/xamlc/demo/test.xaml b/mcs/tools/xamlc/demo/test.xaml
index 3135e01b33e..2aeceeaab1c 100644
--- a/mcs/tools/xamlc/demo/test.xaml
+++ b/mcs/tools/xamlc/demo/test.xaml
@@ -1,10 +1,19 @@
<?Mapping ClrNamespace="Xaml.TestVocab.Console" Assembly="TestVocab" XmlNamespace="console" ?>
-<ConsoleApp xmlns="console">
+<ConsoleApp xmlns="console"
+ xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"
+ x:Class="DemoConsoleApp">
<ConsoleWriter>IT BEGINS!</ConsoleWriter>
<ConsoleWriter Text="Hello World" />
<ConsoleWriter>
<ConsoleApp.Repetitions>3</ConsoleApp.Repetitions>
<ConsoleWriter.Text>Goodbye.</ConsoleWriter.Text>
</ConsoleWriter>
+ <x:Code><![CDATA[
+ public static void Main(string[] args)
+ {
+ Xaml.TestVocab.Console.ConsoleApp c = new DemoConsoleApp();
+ c.Run();
+ }
+ ]]></x:Code>
</ConsoleApp>