public void setData(System.Reflection.PropertyInfo info, object target, string propertyName, string value) { switch (info.PropertyType.ToString()) { case "System.Drawing.Color": info.SetValue(target, YColor.fromString(value).toColor(), null); break; case "System.Windows.Forms.FormBorderStyle": /* info.SetValue(target, GenericProperties.BordersModeFromString(value),null);*/ break; default: info.SetValue(target, value, null); break; } }
public void loadProperties(XmlNode initData, Form Owner, Object o) { string value; ownerForm = Owner; if (initData != null) { foreach (var p in o.GetType().GetProperties()) { if (p.CanWrite) { foreach (XmlNode node in initData.ChildNodes) { if (p.Name == node.Name) { Object target = p.GetValue(o, null); object[] attrs = p.GetCustomAttributes(true); bool Mustload = true; foreach (object a in attrs) { if (a is NotSavedInXMLAttribute) { Mustload = !((NotSavedInXMLAttribute)a).mustSave; } } if (Mustload) { if (IsStructured(target)) { loadProperties(node, Owner, target); } else if (p.PropertyType.IsEnum) { p.SetValue(o, Enum.Parse(p.PropertyType, node.Attributes["value"].InnerText, true), null); break; } else { switch (p.PropertyType.ToString()) { case "System.Boolean": p.SetValue(o, (node.Attributes["value"].InnerText.ToUpper() == "TRUE"), null); break; case "System.Double": double d = (XmlFileVersion >= 2.1) ? Convert.ToDouble(node.Attributes["value"].InnerText, CultureInfo.InvariantCulture) : Convert.ToDouble(node.Attributes["value"].InnerText); p.SetValue(o, d, null); break; case "System.Int32": p.SetValue(o, Int32.Parse(node.Attributes["value"].InnerText), null); break; case "System.String": p.SetValue(o, node.Attributes["value"].InnerText, null); break; case "System.Drawing.Font": System.Drawing.FontStyle style = System.Drawing.FontStyle.Regular; var values = Enum.GetValues(typeof(System.Drawing.FontStyle)); string attr = node.Attributes["style"].InnerText; foreach (var v in values) { if (attr.IndexOf(v.ToString()) >= 0) { style |= (System.Drawing.FontStyle)v; } } float size = XmlFileVersion >= 2.1 ? float.Parse(node.Attributes["size"].InnerText, CultureInfo.InvariantCulture) : float.Parse(node.Attributes["size"].InnerText); p.SetValue(o, new Font(node.Attributes["value"].InnerText, size, style), null); break; case "System.Drawing.Color": value = node.Attributes["value"].InnerText; p.SetValue(o, colorConverter.colorFromHex(value), null); break; case "YoctoVisualisation.doubleNan": //value = node.Attributes["value"].InnerText; double dvalue = (XmlFileVersion >= 2.1) ? Convert.ToDouble(node.Attributes["value"].InnerText, CultureInfo.InvariantCulture) : Convert.ToDouble(node.Attributes["value"].InnerText); p.SetValue(o, new doubleNan(dvalue), null); break; case "YDataRendering.xAxisPosition": double xpos = XmlFileVersion >= 2.1 ? Double.Parse(node.Attributes["value"].InnerText, CultureInfo.InvariantCulture) : Double.Parse(node.Attributes["value"].InnerText); bool rel = (node.Attributes["relative"].InnerText.ToUpper() == "TRUE"); p.SetValue(o, new xAxisPosition(xpos, rel), null); break; case "System.Windows.Media.FontFamily": value = node.Attributes["value"].InnerText; p.SetValue(o, new FontFamily(value), null); break; case "YColors.YColor": value = node.Attributes["value"].InnerText; p.SetValue(o, YColor.fromString(value), null); break; case "YoctoVisualisation.CustomYSensor": value = node.Attributes["value"].InnerText; if ((value.ToUpper() != "NULL") && (value != "")) { CustomYSensor s = sensorsManager.AddNewSensor(value); p.SetValue(o, s, null); } else { p.SetValue(o, sensorsManager.getNullSensor(), null); } break; default: throw new ArgumentException("Initialization from XML file: unhandled data type: (" + p.PropertyType.ToString() + ")"); } } } } } } } } }