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-05 17:23:57 +0400
committerIain McCoy <iainmc@mono-cvs.ximian.com>2005-07-05 17:23:57 +0400
commit67874e02b3fbb6483ba50c4be1add4dfdcf6ba70 (patch)
tree254020ca99097854a5c4b39738c2fa7f0a7d3b4d /mcs/class/PresentationFramework
parent2ac37c2e2abe5ad921e75a08114c62959c0bd677 (diff)
2005-07-05 Iain McCoy <iain@mccoy.id.au>
* Mono.Windows.Serialization/XamlParser.cs, Mono.Windows.Serialization/XamlWriter.cs, Mono.Windows.Serialization/CodeWriter.cs: add support for attached properties as attributes, supplementing the existing support for attached properties as elements svn path=/trunk/mcs/; revision=46945
Diffstat (limited to 'mcs/class/PresentationFramework')
-rw-r--r--mcs/class/PresentationFramework/ChangeLog8
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs6
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs64
3 files changed, 54 insertions, 24 deletions
diff --git a/mcs/class/PresentationFramework/ChangeLog b/mcs/class/PresentationFramework/ChangeLog
index 645b2b023df..c2499135815 100644
--- a/mcs/class/PresentationFramework/ChangeLog
+++ b/mcs/class/PresentationFramework/ChangeLog
@@ -2,6 +2,14 @@
* Mono.Windows.Serialization/XamlParser.cs,
Mono.Windows.Serialization/XamlWriter.cs,
+ Mono.Windows.Serialization/CodeWriter.cs: add support for attached
+ properties as attributes, supplementing the existing support for
+ attached properties as elements
+
+2005-07-05 Iain McCoy <iain@mccoy.id.au>
+
+ * Mono.Windows.Serialization/XamlParser.cs,
+ Mono.Windows.Serialization/XamlWriter.cs,
Mono.Windows.Serialization/CodeWriter.cs: add support for delegate
properties and for events
* Mono.Windows.Serialization/XamlParser.cs,
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
index 7f52ea08a13..717aad9795a 100644
--- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/CodeWriter.cs
@@ -132,10 +132,8 @@ namespace Mono.Windows.Serialization {
public void CreateAttachedProperty(Type attachedTo, string propertyName, Type propertyType)
{
string varName = "temp";
- if (tempIndex != 0) {
- varName += tempIndex;
- tempIndex += 1;
- }
+ varName += tempIndex;
+ tempIndex += 1;
CodeVariableDeclarationStatement decl = new CodeVariableDeclarationStatement(propertyType, varName);
constructor.Statements.Add(decl);
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
index a1a9dd62962..fa49d898dd0 100644
--- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/XamlParser.cs
@@ -223,28 +223,13 @@ namespace Mono.Windows.Serialization {
}
}
+
void parseAttachedPropertyElement(string attachedTo, string propertyName)
{
- Type typeAttachedTo = null;
- FieldInfo propField;
- 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 + ")");
- foreach (ParserState state in oldStates) {
- if (state.type == CurrentType.Object &&
- ((Type)state.obj).Name == attachedTo) {
- typeAttachedTo = (Type)state.obj;
- break;
- }
- }
- if (typeAttachedTo == null)
- throw new Exception("Nothing to attach to: " + attachedTo + "." + propertyName);
- propField = typeAttachedTo.GetField(propertyName + "Property");
- if (propField == null)
- throw new Exception("Property " + propertyName + " does not exist on " + attachedTo);
- dp = (DependencyProperty)propField.GetValue(null);
+ ensureDependencyObject(currentType);
+ Type typeAttachedTo = findTypeToAttachTo(attachedTo, propertyName);
+ DependencyProperty dp = getDependencyProperty(typeAttachedTo, propertyName);
oldStates.Add(currentState);
currentState = new ParserState();
@@ -346,11 +331,50 @@ namespace Mono.Windows.Serialization {
return true;
}
+ void ensureDependencyObject(Type currentType)
+ {
+ if (!currentType.IsSubclassOf(typeof(System.Windows.DependencyObject)))
+ throw new Exception("Attached properties can only be set on "+
+ "DependencyObjects (not " + currentType.Name + ")");
+ }
+ Type findTypeToAttachTo(string attachedTo, string propertyName)
+ {
+ Type typeAttachedTo = null;
+ foreach (ParserState state in oldStates) {
+ if (state.type == CurrentType.Object &&
+ ((Type)state.obj).Name == attachedTo) {
+ typeAttachedTo = (Type)state.obj;
+ break;
+ }
+ }
+ if (typeAttachedTo == null)
+ throw new Exception("Nothing to attach to: " + attachedTo + "." + propertyName);
+ return typeAttachedTo;
+ }
+ DependencyProperty getDependencyProperty(Type typeAttachedTo, string propertyName)
+ {
+ FieldInfo propField = typeAttachedTo.GetField(propertyName + "Property");
+ if (propField == null)
+ throw new Exception("Property " + propertyName + " does not exist on " + typeAttachedTo.Name);
+ return (DependencyProperty)propField.GetValue(null);
+ }
void parseContextPropertyAttribute()
{
- throw new NotImplementedException("parseContextPropertyAttribute");
+ int index = reader.LocalName.LastIndexOf('.');
+ string attachedTo = reader.LocalName.Substring(0, index);
+ string propertyName = reader.LocalName.Substring(index + 1);
+
+ Type currentType = (Type)currentState.obj;
+ ensureDependencyObject(currentType);
+ Type typeAttachedTo = findTypeToAttachTo(attachedTo, propertyName);
+ DependencyProperty dp = getDependencyProperty(typeAttachedTo, propertyName);
+
+ writer.CreateAttachedProperty(typeAttachedTo, propertyName, dp.PropertyType);
+ writer.CreateAttachedPropertyText(reader.Value, dp.PropertyType,
+ getTypeConverter(dp.PropertyType));
+ writer.EndAttachedProperty();
}
void parseEndElement()