diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2015-06-06 11:37:41 +0200 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2015-06-06 11:37:42 +0200 |
| commit | 0128eebf85f3a0c29b2e6b63f966ddd27205818c (patch) | |
| tree | b431e74f6a747c26dc7a0db03b0427943567370f /src/GraphicObjects/GraphicObject.cs | |
| parent | a7363d1f7e4eb1611e4ab522c8cf381b70570b7e (diff) | |
- generic conversion through Parse method for custom type xml
attribute
Diffstat (limited to 'src/GraphicObjects/GraphicObject.cs')
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 0a402f12..9e55d1cf 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -213,7 +213,7 @@ namespace go registerForGraphicUpdate ();
}
}
- [XmlAttributeAttribute()][DefaultValue(2)]
+ [XmlAttributeAttribute()][DefaultValue(2.0)]
public virtual double CornerRadius {
get { return _cornerRadius; }
set {
@@ -314,23 +314,21 @@ namespace go DefaultValueAttribute dv = o as DefaultValueAttribute;
if (dv != null) {
- if (pi.PropertyType == typeof(Color))
- pi.SetValue (this, Color.Parse ((string)dv.Value), null);
- else if (pi.PropertyType == typeof(Font))
- pi.SetValue (this, Font.Parse ((string)dv.Value), null);
- else if (pi.PropertyType == typeof(Picture))
- pi.SetValue (this, Picture.Parse ((string)dv.Value), null);
- else if (pi.PropertyType == typeof(Size))
- pi.SetValue (this, Size.Parse ((string)dv.Value), null);
- else
- pi.SetValue (this, dv.Value, null);
- continue;
- }
-
- //Debug.WriteLine (o.ToString ());
+ object defaultValue = dv.Value;
+ //avoid system types automaticaly converted by parser
+ if (defaultValue != null && !pi.PropertyType.Namespace.StartsWith("System")) {
+ if (pi.PropertyType != defaultValue.GetType()) {
+ MethodInfo miParse = pi.PropertyType.GetMethod ("Parse", BindingFlags.Static | BindingFlags.Public);
+ if (miParse != null) {
+ pi.SetValue (this, miParse.Invoke (null, new object[]{ defaultValue }), null);
+ continue;
+ }
+ }
+ }
+ pi.SetValue (this, defaultValue, null);
+ }
}
}
-
}
public virtual GraphicObject FindByName(string nameToFind){
@@ -749,18 +747,21 @@ namespace go string v = reader.GetAttribute (name);
if (string.IsNullOrEmpty (v)) {
- //TODO: maybe find another way to convert correctely colors default values
- if (pi.PropertyType == typeof(Color))
- pi.SetValue (this, Color.Parse ((string)defaultValue), null);
- else if (pi.PropertyType == typeof(Font))
- pi.SetValue (this, Font.Parse ((string)defaultValue), null);
- else if (pi.PropertyType == typeof(Picture))
- pi.SetValue (this, Picture.Parse ((string)defaultValue), null);
- else if (pi.PropertyType == typeof(Size))
- pi.SetValue (this, Size.Parse ((string)defaultValue), null);
- else
- pi.SetValue (this, defaultValue, null);
+ //avoid system types automaticaly converted by parser
+ if (defaultValue != null && !pi.PropertyType.Namespace.StartsWith("System")) {
+ if (pi.PropertyType != defaultValue.GetType()) {
+ MethodInfo miParse = pi.PropertyType.GetMethod ("Parse", BindingFlags.Static | BindingFlags.Public);
+ if (miParse != null) {
+ pi.SetValue (this, miParse.Invoke (null, new object[]{ defaultValue }), null);
+ continue;
+ }
+ }
+ }
+
+ pi.SetValue (this, defaultValue, null);
+
} else {
+
if (v.StartsWith("{")) {
//binding
if (!v.EndsWith("}"))
|