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-08-28 16:27:42 +0400
committerIain McCoy <iainmc@mono-cvs.ximian.com>2005-08-28 16:27:42 +0400
commitb3c280bb493afaf552bd9db8cf31b3129de72c21 (patch)
tree5dbe2cb095935e7fae0de0523b74cf4a7ee6c45a /mcs/class/PresentationFramework
parent0fdf4747bc8ea66b9b6ac25d59928d5331f63958 (diff)
2005-08-28 Iain McCoy <iain@mccoy.id.au>
* System.Windows.Serialization/Parser.cs: a bit more refactoring to reduce code duplication * Mono.Windows.Serialization/ParserToCode.cs: similarly, refactoring to reduce code duplication svn path=/trunk/mcs/; revision=49023
Diffstat (limited to 'mcs/class/PresentationFramework')
-rw-r--r--mcs/class/PresentationFramework/ChangeLog7
-rw-r--r--mcs/class/PresentationFramework/Mono.Windows.Serialization/ParserToCode.cs21
-rw-r--r--mcs/class/PresentationFramework/System.Windows.Serialization/Parser.cs34
3 files changed, 34 insertions, 28 deletions
diff --git a/mcs/class/PresentationFramework/ChangeLog b/mcs/class/PresentationFramework/ChangeLog
index 980ce218bd4..714d24624c5 100644
--- a/mcs/class/PresentationFramework/ChangeLog
+++ b/mcs/class/PresentationFramework/ChangeLog
@@ -1,5 +1,12 @@
2005-08-28 Iain McCoy <iain@mccoy.id.au>
+ * System.Windows.Serialization/Parser.cs: a bit more refactoring to
+ reduce code duplication
+ * Mono.Windows.Serialization/ParserToCode.cs: similarly, refactoring
+ to reduce code duplication
+
+2005-08-28 Iain McCoy <iain@mccoy.id.au>
+
* Mono.Windows.Serialization/ParserConsumerBase.cs: move dispatching
to handlers based on nodes returned from the parser into a base class
* Mono.Windows.Serialization/ParserToCode.cs: use ParserConsumerBase
diff --git a/mcs/class/PresentationFramework/Mono.Windows.Serialization/ParserToCode.cs b/mcs/class/PresentationFramework/Mono.Windows.Serialization/ParserToCode.cs
index 2c0e526948b..95818a309ad 100644
--- a/mcs/class/PresentationFramework/Mono.Windows.Serialization/ParserToCode.cs
+++ b/mcs/class/PresentationFramework/Mono.Windows.Serialization/ParserToCode.cs
@@ -231,11 +231,7 @@ namespace Mono.Windows.Serialization {
public override void CreateEventDelegate(string functionName, Type eventDelegateType)
{
debug();
- CodeExpression expr = new CodeObjectCreateExpression(
- eventDelegateType,
- new CodeMethodReferenceExpression(
- new CodeThisReferenceExpression(),
- functionName));
+ CodeExpression expr = buildDelegate(eventDelegateType, functionName);
CodeAttachEventStatement attach = new CodeAttachEventStatement(
(CodeEventReferenceExpression)peek(),
expr);
@@ -246,16 +242,21 @@ namespace Mono.Windows.Serialization {
public override void CreatePropertyDelegate(string functionName, Type propertyType)
{
debug();
- CodeExpression expr = new CodeObjectCreateExpression(
- propertyType,
- new CodeMethodReferenceExpression(
- new CodeThisReferenceExpression(),
- functionName));
+ CodeExpression expr = buildDelegate(propertyType, functionName);
CodeAssignStatement assignment = new CodeAssignStatement(
(CodeExpression)peek(),
expr);
constructor.Statements.Add(assignment);
}
+ private CodeExpression buildDelegate(Type propertyType, string functionName)
+ {
+ return new CodeObjectCreateExpression(
+ propertyType,
+ new CodeMethodReferenceExpression(
+ new CodeThisReferenceExpression(),
+ functionName));
+
+ }
private CodeExpression fetchConverter(Type propertyType)
{
diff --git a/mcs/class/PresentationFramework/System.Windows.Serialization/Parser.cs b/mcs/class/PresentationFramework/System.Windows.Serialization/Parser.cs
index 9477cb877fc..b715ffffce7 100644
--- a/mcs/class/PresentationFramework/System.Windows.Serialization/Parser.cs
+++ b/mcs/class/PresentationFramework/System.Windows.Serialization/Parser.cs
@@ -96,7 +96,6 @@ namespace System.Windows.Serialization {
MethodInfo setter = attachedTo.GetMethod("Set" + propertyName);
- Console.WriteLine(attachedTo.GetType()+ ".Set" + propertyName + "(" + peek().GetType() + ", " + value.GetType() + ")");
setter.Invoke(null, new object[] { peek(), value});
}
@@ -122,11 +121,7 @@ namespace System.Windows.Serialization {
public override void CreatePropertyText(string text, Type propertyType)
{
- object value = text;
- if (propertyType != typeof(string)) {
- TypeConverter tc = TypeDescriptor.GetConverter(propertyType);
- value = tc.ConvertFromString(text);
- }
+ object value = convertText(propertyType, text);
storeToProperty(value);
}
@@ -138,7 +133,7 @@ namespace System.Windows.Serialization {
}
public override void EndPropertyObject(Type destType)
{
- object value = convertPropertyObjectValue(destType);
+ object value = convertPropertyObjectValue(destType, pop());
storeToProperty(value);
}
private void storeToProperty(object value)
@@ -147,17 +142,24 @@ namespace System.Windows.Serialization {
object o = peek(1);
p.SetValue(o, value, null);
}
- private object convertPropertyObjectValue(Type destType)
+ private object convertPropertyObjectValue(Type destType, object value)
{
- object value = pop();
Type sourceType = value.GetType();
- Debug.WriteLine("ObjectWriter: EndPropertyObject has a " + value + value.GetType() + ", needs a " + destType);
if (destType != sourceType && !sourceType.IsSubclassOf(destType)) {
TypeConverter tc = TypeDescriptor.GetConverter(sourceType);
value = tc.ConvertTo(value, destType);
}
return value;
}
+ private object convertText(Type propertyType, string text)
+ {
+ if (propertyType != typeof(string)) {
+ TypeConverter tc = TypeDescriptor.GetConverter(propertyType);
+ return tc.ConvertFromString(text);
+ } else {
+ return text;
+ }
+ }
public override void CreateDependencyPropertyObject(Type type, string name)
{
@@ -165,17 +167,13 @@ namespace System.Windows.Serialization {
}
public override void EndDependencyPropertyObject(Type finalType)
{
- push(convertPropertyObjectValue(finalType));
+ push(convertPropertyObjectValue(finalType, pop()));
}
// top of stack is reference to an attached property
public override void CreateDependencyPropertyText(string text, Type propertyType)
{
- object value = text;
- if (propertyType != typeof(string)) {
- TypeConverter tc = TypeDescriptor.GetConverter(propertyType);
- value = tc.ConvertFromString(text);
- }
+ object value = convertText(propertyType, text);
push(value);
}
@@ -215,12 +213,12 @@ namespace System.Windows.Serialization {
{
object v = objects[objects.Count - 1];
objects.RemoveAt(objects.Count - 1);
- Debug.WriteLine("ObjectWriter POPPING");
+ Debug.WriteLine("ObjectWriter: POPPING");
return v;
}
private void push(object v)
{
- Debug.WriteLine("ObjectWriter PUSHING " + v);
+ Debug.WriteLine("ObjectWriter: PUSHING " + v);
objects.Add(v);
}
}