StringToValue() public method

public StringToValue ( string value ) : object
value string
return object
        ArrayList AddSubprops(XmlNodeList nodes, ItemGroup group, ClassDescriptor klass)
        {
            ArrayList list = null;

            // Sub-properties can have a name+value (which checks for the value of a
            // property) or a method name, which should return true if the item has
            // to be disabled/hidden.

            foreach (XmlElement elem in nodes)
            {
                string name = elem.GetAttribute("name");
                if (name.Length > 0)
                {
                    string value = elem.GetAttribute("value");

                    PropertyDescriptor prop = (PropertyDescriptor)group[name];
                    if (prop == null)
                    {
                        prop = (PropertyDescriptor)klass[name];
                    }
                    if (prop == null)
                    {
                        throw new ArgumentException("Bad sub-prop " + name);
                    }
                    if (list == null)
                    {
                        list = new ArrayList();
                    }

                    DepInfo info = new DepInfo();
                    info.Property = prop;
                    info.Value    = prop.StringToValue(value);
                    list.Add(info);
                }
                else if ((name = elem.GetAttribute("check")).Length > 0)
                {
                    DepInfo info = new DepInfo();
                    info.CheckName = name;
                    if (list == null)
                    {
                        list = new ArrayList();
                    }
                    list.Add(info);
                }
                else
                {
                    throw new ArgumentException("Bad sub-prop");
                }
            }
            return(list);
        }
Beispiel #2
0
        public static void ReadProperty(ClassDescriptor klass, ObjectWrapper wrapper, object wrapped, XmlElement prop_node)
        {
            string             name = prop_node.GetAttribute("name");
            PropertyDescriptor prop = klass [name] as PropertyDescriptor;

            if (prop == null || !prop.CanWrite)
            {
                return;
            }

            string strval = prop_node.InnerText;

            // Skip translation context
            if (prop_node.GetAttribute("context") == "yes" && strval.IndexOf('|') != -1)
            {
                strval = strval.Substring(strval.IndexOf('|') + 1);
            }

            object value = prop.StringToValue(strval);

            prop.SetValue(wrapped, value);

            if (prop.Translatable)
            {
                if (prop_node.GetAttribute("translatable") != "yes")
                {
                    prop.SetTranslated(wrapped, false);
                }
                else
                {
                    prop.SetTranslated(wrapped, true);
                    if (prop_node.GetAttribute("context") == "yes")
                    {
                        strval = prop_node.InnerText;
                        int bar = strval.IndexOf('|');
                        if (bar != -1)
                        {
                            prop.SetTranslationContext(wrapped, strval.Substring(0, bar));
                        }
                    }

                    if (prop_node.HasAttribute("comments"))
                    {
                        prop.SetTranslationComment(wrapped, prop_node.GetAttribute("comments"));
                    }
                }
            }
        }