Esempio n. 1
0
        public virtual void LoadFromXml(XmlNode node)
        {
            PropertyName = XmlUtil.GetAttribute(node, XMLATT_typeName);
            XmlNode childNode = node.SelectSingleNode(XML_Child);

            if (childNode != null)
            {
                Type t = XmlUtil.GetLibTypeAttribute(childNode);
                MathPropertyPointer cmp = (MathPropertyPointer)Activator.CreateInstance(t);
                Child = cmp;
                cmp.LoadFromXml(childNode);
            }
        }
        public override Object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
        {
            string sv = value as string;

            if (sv != null && context != null)
            {
                MathPropertyPointer pv = context.PropertyDescriptor.GetValue(context.Instance) as MathPropertyPointer;
                if (pv != null)
                {
                    if (sv.Length == 0)
                    {
                        pv = new MathPropertyPointerConstant();
                        context.PropertyDescriptor.SetValue(context.Instance, pv);
                    }
                    else
                    {
                        MathPropertyPointerConstant mpc = pv as MathPropertyPointerConstant;
                        if (mpc != null)
                        {
                            mpc.Instance = sv;
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(pv.PropertyName))
                            {
                                pv          = new MathPropertyPointerConstant();
                                pv.Instance = sv;
                            }
                        }
                    }
                    return(pv);
                }
                else
                {
                    context.PropertyDescriptor.SetValue(context.Instance, value);
                }
                return(value);
            }
            else
            {
                return(base.ConvertFrom(context, culture, value));
            }
        }
Esempio n. 3
0
        public void LoadFromString(string data)
        {
            if (string.IsNullOrEmpty(data))
            {
                throw new MathException("cannot call LoadFromString with null");
            }
            data = data.Trim();
            if (string.IsNullOrEmpty(data))
            {
                throw new MathException("cannot call LoadFromString with empty data");
            }
            int pos = data.IndexOf('.');

            if (pos >= 0)
            {
                if (pos == 0)
                {
                    throw new MathException("Invalid data [{0}] calling LoadFromString", data);
                }
                string s = data.Substring(0, pos);
                s = s.Trim();
                if (string.IsNullOrEmpty(s))
                {
                    throw new MathException("Invalid data [{0}] calling LoadFromString. ", data);
                }
                PropertyName = s;
                data         = data.Substring(pos + 1);
                data         = data.Trim();
                if (!string.IsNullOrEmpty(data))
                {
                    _child = new MathPropertyPointer();
                    _child.LoadFromString(data);
                }
            }
            else
            {
                PropertyName = data;
            }
        }