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;
            }
        }
Exemplo n.º 2
0
        // Direction : settings From Target
        static public void copyProperty_SFT(object rootTarget, object source, string propertySourceName, List <string> path, PropFilter filterAllow)
        {
            System.Reflection.PropertyInfo tinfo = null;
            System.Reflection.PropertyInfo sinfo = null;
            string ttype = "";
            string stype = "";
            object FinalTarget;
            object TerminalSource;

            computePropertyAccess_SFT(rootTarget, source, propertySourceName, path, out tinfo, out sinfo, out ttype, out stype, out FinalTarget, out TerminalSource);

            if (tinfo == null)
            {
                return;          // the property does not exists in the widget
            }
            if ((stype == "System.Drawing.Color") && (ttype == "YColors.YColor"))
            {
                tinfo.SetValue(FinalTarget, YColor.fromColor((Color)TerminalSource), null);
            }
            else if ((stype == "System.Double") && (ttype == "YoctoVisualisation.doubleNan"))
            {
                tinfo.SetValue(FinalTarget, new doubleNan((double)TerminalSource), null);
            }
            else
            if ((stype == "YDataRendering.DataTracker+DataPrecision") && (ttype == "YoctoVisualisation.DataTrackerDescription+DataPrecision"))
            { // Mono doesn't like enums implicit conversions
                YDataRendering.DataTracker.DataPrecision svalue = (YDataRendering.DataTracker.DataPrecision)TerminalSource;
                int temp = (int)svalue;
                YoctoVisualisation.DataTrackerDescription.DataPrecision tvalue = (YoctoVisualisation.DataTrackerDescription.DataPrecision)(temp);
                tinfo.SetValue(FinalTarget, tvalue, null);
            }

            else
            {
                tinfo.SetValue(FinalTarget, TerminalSource, null);
            }
        }
Exemplo n.º 3
0
        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() + ")");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }