diff --git a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/XmlDesignerGenerator.cs b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/XmlDesignerGenerator.cs index 037099cca7..b403d00439 100644 --- a/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/XmlDesignerGenerator.cs +++ b/src/AddIns/DisplayBindings/FormsDesigner/Project/Src/DesignerGenerator/XmlDesignerGenerator.cs @@ -156,12 +156,15 @@ namespace ICSharpCode.FormsDesigner } } else if (pd.ShouldSerializeValue(o) && pd.IsBrowsable) { XmlAttribute valueAttribute = doc.CreateAttribute("value"); - if (propertyValue is Font) { - Font f = (Font)propertyValue; - propertyValue = new Font(f.FontFamily, (float)Math.Round(f.Size)); - } - valueAttribute.InnerText = propertyValue == null ? null : propertyValue.ToString(); + if (propertyValue == null) { + valueAttribute.InnerText = null; + } else if (propertyValue is Color) { + valueAttribute.InnerText = propertyValue.ToString(); + } else { + TypeConverter typeConv = TypeDescriptor.GetConverter(pd.PropertyType); + valueAttribute.InnerText = typeConv.ConvertToInvariantString(propertyValue); + } childEl.Attributes.Append(valueAttribute); childNodes.Insert(0, childEl); } diff --git a/src/Main/Base/Project/Src/Gui/XmlForms/Lib/XmlLoader.cs b/src/Main/Base/Project/Src/Gui/XmlForms/Lib/XmlLoader.cs index 18e5c31221..35e06629db 100644 --- a/src/Main/Base/Project/Src/Gui/XmlForms/Lib/XmlLoader.cs +++ b/src/Main/Base/Project/Src/Gui/XmlForms/Lib/XmlLoader.cs @@ -40,7 +40,6 @@ namespace ICSharpCode.SharpDevelop.Gui.XmlForms IObjectCreator objectCreator = new DefaultObjectCreator(); IPropertyValueCreator propertyValueCreator = null; - readonly static Regex fontRegex = new Regex(@"Name=(\.+)\,\s+Size=(\d+)"); readonly static Regex propertySet = new Regex(@"(?[\w]+)\s*=\s*(?[\w\d]+)", RegexOptions.Compiled); /// @@ -298,23 +297,10 @@ namespace ICSharpCode.SharpDevelop.Gui.XmlForms } else { propertyInfo.SetValue(o, Color.FromName(color), null); } - } else if (propertyInfo.PropertyType == typeof(Font)) { - Match m = fontRegex.Match(val); - if (m.Success) { - propertyInfo.SetValue(o, new Font(m.Groups[0].Value, Int32.Parse(m.Groups[1].Value)), null); - } else { - // set some default font here - propertyInfo.SetValue(o, SystemInformation.MenuFont, null); - } - } else if (propertyInfo.PropertyType == typeof(System.Windows.Forms.Cursor)) { - string[] cursor = val.Split('[', ']', ' ', ':'); - PropertyInfo cursorProperty = typeof(System.Windows.Forms.Cursors).GetProperty(cursor[3]); - if (cursorProperty != null) { - propertyInfo.SetValue(o, cursorProperty.GetValue(null, null), null); - } } else { if (val.Length > 0) { - propertyInfo.SetValue(o, Convert.ChangeType(val, propertyInfo.PropertyType), null); + TypeConverter conv = TypeDescriptor.GetConverter(propertyInfo.PropertyType); + propertyInfo.SetValue(o, conv.ConvertFromInvariantString(val), null); } } } catch (Exception e) {