public void SetConfigValueFromString(FieldPropertyDescriptorByRef config, string value) { object valueConverted = null; if (config.FieldPropertyDescriptor.PropertyType.IsEnum) { valueConverted = Enum.Parse(config.FieldPropertyDescriptor.PropertyType, value); } else { valueConverted = Convert.ChangeType(value, config.FieldPropertyDescriptor.PropertyType); } config.FieldPropertyDescriptor.SetValue(this, valueConverted); }
public SiteSettingViewModel(SiteViewModel site, FieldPropertyDescriptorByRef propertyDescriptor) : base(Consts.KEY_NAME, propertyDescriptor.DisplayName) { Site = site; PropertyDescriptor = propertyDescriptor; _nameProperty = new WProperty(typeof(string), propertyDescriptor.DisplayName); _descriptionProperty = new WProperty(typeof(string), propertyDescriptor.Description); _isPasswordProperty = new WProperty(typeof(bool), propertyDescriptor.IsPassword); string valueAsString = site.Site.GetConfigValueAsString(propertyDescriptor); _valueProperty = new WProperty(typeof(string), propertyDescriptor.IsPassword ? new string('*', valueAsString.Length) : valueAsString); _newValueProperty = new WProperty(typeof(string), valueAsString); _possibleValuesProperty = new WProperty(typeof(ItemsList), null); Command = new MethodDelegateCommand(() => Configure()); }
public string GetConfigValueAsString(FieldPropertyDescriptorByRef config) { object result = config.FieldPropertyDescriptor.GetValue(this); return(result == null ? string.Empty : result.ToString()); }