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-08 16:32:27 +0400
committerIain McCoy <iainmc@mono-cvs.ximian.com>2005-07-08 16:32:27 +0400
commit3b8170b02746dfc718c13e324730ed6e83fac5ad (patch)
tree36c69ade437e2793a5e6d080570b012a927b076a /mcs/class/PresentationFramework
parentb1e4a4e3256614f4c180f0d150b593391ce447ae (diff)
2005-07-06 Iain McCoy <iain@mccoy.id.au>
* demo/test.xaml: add use of x:Name attribute * Mono.Windows.Serialization/XamlParser.cs, Mono.Windows.Serialization/XamlWriter.cs, Mono.Windows.Serialization/CodeWriter.cs: support for x:Name attributes and for considering Name properties to have the same affect. svn path=/trunk/mcs/; revision=47091
Diffstat (limited to 'mcs/class/PresentationFramework')
-rw-r--r--mcs/class/PresentationFramework/ChangeLog8
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs35
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs21
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs2
4 files changed, 44 insertions, 22 deletions
diff --git a/mcs/class/PresentationFramework/ChangeLog b/mcs/class/PresentationFramework/ChangeLog
index 21baffd7d49..32741738996 100644
--- a/mcs/class/PresentationFramework/ChangeLog
+++ b/mcs/class/PresentationFramework/ChangeLog
@@ -1,3 +1,11 @@
+2005-07-08 Iain McCoy <iain@mccoy.id.au>
+
+ * Mono.Windows.Serialization/XamlParser.cs,
+ Mono.Windows.Serialization/XamlWriter.cs,
+ Mono.Windows.Serialization/CodeWriter.cs: support for x:Name
+ attributes and for considering Name properties to have the same
+ affect.
+
2005-07-06 Iain McCoy <iain@mccoy.id.au>
* Mono.Windows.Serialization/CodeWriter.cs: cleaned up a little, added
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
index 8ac2792deca..5ed0c3118fb 100644
--- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
@@ -89,13 +89,19 @@ namespace Mono.Windows.Serialization {
// bottom of stack holds CodeVariableReferenceExpression
// pushes a reference to the new current type
- public void CreateObject(Type type)
+ public void CreateObject(Type type, string varName)
{
- 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;
+ 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;
@@ -104,16 +110,23 @@ namespace Mono.Windows.Serialization {
varName += (int)nameClashes[varName];
}
- CodeVariableDeclarationStatement declaration =
- new CodeVariableDeclarationStatement(type,
- varName,
- new CodeObjectCreateExpression(type));
+
+ 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);
CodeMethodInvokeExpression addChild = new CodeMethodInvokeExpression(
(CodeExpression)objects[objects.Count - 1],
"AddChild",
varRef);
- constructor.Statements.Add(declaration);
constructor.Statements.Add(addChild);
objects.Add(varRef);
}
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
index 749f9feefb7..369c6532fea 100644
--- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
@@ -242,17 +242,18 @@ namespace Mono.Windows.Serialization {
void parseObjectElement()
{
Type parent;
- string objectName = null;
bool isEmpty = reader.IsEmptyElement;
parent = mapper.GetType(reader.NamespaceURI, reader.Name);
- objectName = reader.GetAttribute("Class", XAML_NAMESPACE);
if (parent.GetInterface("System.Windows.Serialization.IAddChild") == null)
{} //TODO: throw exception
if (currentState == null) {
- createTopLevel(parent.AssemblyQualifiedName, objectName);
+ createTopLevel(parent.AssemblyQualifiedName, reader.GetAttribute("Class", XAML_NAMESPACE));
} else {
- addChild(parent);
+ string name = reader.GetAttribute("Name", XAML_NAMESPACE);
+ if (name == null)
+ name = reader.GetAttribute("Name", reader.NamespaceURI);
+ addChild(parent, name);
}
if (reader.MoveToFirstAttribute()) {
@@ -275,21 +276,21 @@ namespace Mono.Windows.Serialization {
}
}
- void createTopLevel(string parentName, string objectName)
+ void createTopLevel(string parentName, string className)
{
Type t = Type.GetType(parentName);
currentState = new ParserState();
currentState.type = CurrentType.Object;
currentState.obj = t;
- if (objectName == null) {
- objectName = "derived" + t.Name;
+ if (className == null) {
+ className = "derived" + t.Name;
}
- writer.CreateTopLevel(t, objectName);
+ writer.CreateTopLevel(t, className);
}
- void addChild(Type type)
+ void addChild(Type type, string objectName)
{
- writer.CreateObject(type);
+ writer.CreateObject(type, objectName);
oldStates.Add(currentState);
currentState = new ParserState();
currentState.type = CurrentType.Object;
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
index 0c93c74c955..38d7170c94a 100644
--- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlWriter.cs
@@ -33,7 +33,7 @@ namespace Mono.Windows.Serialization {
public interface XamlWriter {
void CreateTopLevel(Type parent, string className);
- void CreateObject(Type type);
+ void CreateObject(Type type, string name);
void CreateElementText(string text);
void EndObject();