public override void FromXml(XmlElement xmlElement)
        {
            FieldDropdown dropdown = mBlock.GetField("MENU") as FieldDropdown;

            if (dropdown == null)
            {
                throw new Exception("FieldDropDown \"MENU\" not found.");
            }

            if (xmlElement.HasAttribute("options"))
            {
                string   optionText = xmlElement.GetAttribute("options");
                string[] options    = optionText.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (options.Length % 2 != 0)
                {
                    throw new Exception(string.Format("Xml serialization for mutation {0} is damaged", MutatorId));
                }

                FieldDropdownMenu[] menu = new FieldDropdownMenu[options.Length / 2];
                for (int i = 0; i < menu.Length; i++)
                {
                    menu[i].Text  = options[i * 2];
                    menu[i].Value = options[i * 2 + 1];
                }
                dropdown.SetOptions(menu);
            }
        }
Exemplo n.º 2
0
        private static FieldDropdown CreateFromJson(JObject json)
        {
            string        fieldName = json["name"].IsString() ? json["name"].ToString() : "FIELDNAME_DEFAULT";
            FieldDropdown field     = new FieldDropdown(fieldName);

            if (json.JsonDataContainsKey("options"))
            {
                field.SetOptions(json["options"] as JArray);
            }

            field.IsImage = json.JsonDataContainsKey("image") && (bool)json["image"];
            return(field);
        }