public void AddProperty(DialogCharacterPropertyDescriptor descr)
 {
     AddProperty(descr, true);
 }
        public Dictionary<int, string> ReadXml(XElement xProperties, List<string> ignoredProperties)
        {
            var res = new Dictionary<int, string>();
            foreach(var xProperty in xProperties.Elements("property"))
            {
                string name,typeStr;
                int id;
                if (!xProperty.TryGetAttribute("name", out name) || !xProperty.TryGetAttribute("id", out id) || !xProperty.TryGetAttribute("type", out typeStr))
                    throw new Exception("Unable to read character's property description: format is incorrect.");

                res.Add(id, name);
                if(ignoredProperties.Contains(name))
                    continue;

                var type = Type.GetType(typeStr);

                DialogCharacterPropertyDescriptor descriptor;
                object defaultValue;
                if (ValueParser.TryParse(xProperty.Value, type, out defaultValue))
                    descriptor = new DialogCharacterPropertyDescriptor(name, type, defaultValue, new Attribute[0]);
                else
                    descriptor = new DialogCharacterPropertyDescriptor(name, type, new Attribute[0]);

                AddProperty(descriptor);
            }

            return res;
        }
 public void AddProperty(string propertyName, Type propertyType)
 {
     var descr = new DialogCharacterPropertyDescriptor(propertyName, propertyType, new Attribute[0]);
     AddProperty(descr, true);
 }
        private void ButtonOkClick(object sender, EventArgs e)
        {
            Type propType;
            object defVal = null;
            bool hasDefVal = _checkBoxDefaultValue.Checked;
            bool defValParsed = false;
            switch(_comboBoxPropType.SelectedItem as string)
            {
                case "Integer":
                    propType = typeof (int);
                    if(hasDefVal)
                    {
                        int intVal;
                        defValParsed = int.TryParse(_textDefaultValue.Text, out intVal);
                        defVal = intVal;
                    }
                    else
                        defVal = default(int);
                    break;
                case "String":
                    propType = typeof (string);
                    if (hasDefVal)
                    {
                        defVal = _textDefaultValue.Text;
                        defValParsed = true;
                    }
                    break;
                case "Boolean":
                    propType = typeof (bool);
                    if (hasDefVal)
                    {
                        bool boolVal;
                        defValParsed = bool.TryParse(_textDefaultValue.Text, out boolVal);
                        defVal = boolVal;
                    }
                    else
                        defVal = default(bool);
                    break;
                default:
                    throw new Exception("Unknown type of property.");
            }

            if(hasDefVal && !defValParsed)
            {
                this.ShowError(string.Format("Default value should be '{0}'.", _comboBoxPropType.SelectedItem));
                return;
            }

            PropertyDescriptor = new DialogCharacterPropertyDescriptor(_textPropertyName.Text, propType, defVal,
                                                                       new Attribute[0]);
            DialogResult = DialogResult.OK;

            Close();
        }