/// <summary> /// Sets the value of this property. /// </summary> public virtual void SetValue(object value) { var context = new SimpleTypeDescriptorContext { Instance = this.Settings, ServiceProvider = GetServiceProvider() }; this.Settings.Value = this.ValueConverter.Value.CanConvertTo(context, typeof(string)) ? this.ValueConverter.Value.ConvertToString(context, value) : string.Empty; }
/// <summary> /// Gets the value of the property. /// </summary> public virtual object GetValue() { var context = new SimpleTypeDescriptorContext { Instance = this.Settings, ServiceProvider = GetServiceProvider() }; if (this.Settings.HasValue()) { return(this.ValueConverter.Value.CanConvertFrom(context, typeof(string)) ? this.ValueConverter.Value.ConvertFromString(context, this.Settings.Value) : string.Empty); } else { return(string.Empty); } }
/// <summary> /// Gets the deserialized <see cref="Collection{T}"/> from the underlying serialized string. /// </summary> public override object GetValue(object component) { var values = new Collection <object>(); var propertySettings = GetPropertySettings(component); if (propertySettings != null) { var value = propertySettings.Value; if (!string.IsNullOrEmpty(value)) { // Exclude displayed caption if (IsDisplayText(value)) { values = new Collection <object>(); } else { // Ask TypeConverter for deserialized value var context = new SimpleTypeDescriptorContext { Instance = component, PropertyDescriptor = this }; if (this.Converter != null && this.Converter.CanConvertFrom(context, typeof(string))) { values = FromObjectToCollection <object>(this.Converter.ConvertFrom(context, CultureInfo.CurrentCulture, value)); } else { values = new Collection <object>(); } } } } if (this.IsReadOnly) { return(new ReadOnlyCollection <object>(values)); } return(values); }