/// <summary> /// Initializes an instance of <see cref="SettingsPropertyInfo{T}"/> class. /// </summary> /// <param name="attr">The settings attribute of the property.</param> /// <param name="prop">The <see cref="PropertyInfo"/> of the property.</param> /// <param name="converterType">The converter of the property.</param> public SettingsPropertyInfo(T attr, PropertyInfo prop, Type converterType) { this.Attribute = attr; this.Property = prop; if (converterType != null) { this.Converter = (ISimpleConverter)converterType.Assembly.CreateInstance(converterType.FullName); } else { this.Converter = SimpleConverter.Create(prop.PropertyType); } }
/// <summary> /// Get or set the value of a property by name. /// </summary> /// <param name="name">A specified name of the property.</param> /// <returns>The value of the specified property. <see langword="null"/> when the name is invalid.</returns> protected object this[string name] { get { if (properties.TryGetValue(name, out SettingsPropertyInfo <T> setting)) { ISimpleConverter converter = setting.Converter; return(converter.ConvertBack(setting.Property.GetValue(this))); } return(null); } set { if (value != null) { if (properties.TryGetValue(name, out SettingsPropertyInfo <T> setting)) { ISimpleConverter converter = setting.Converter; setting.Property.SetValue(this, converter.Convert(value)); } } } }
internal JsonSimpleMapper(ISimpleConverter <T> converter) { _converter = converter; }