public static ISettingsBuilder AddMemoryAdapter( this ISettingsBuilder builder, IDictionary <string, object> data = null, ISettingConverter converter = null) { return(builder.Add(new MemoryAdapter(data), converter)); }
public static ISettingsBuilder LoadFromDictionary( this ISettingsBuilder builder, IDictionary <string, object> dict, ISettingConverter converter = null) { return(builder.Load(new DictionaryLoader(dict), converter)); }
public static ISettingsBuilder AddEnvironmentVariableAdapter( this ISettingsBuilder builder, string prefix = null, ISettingConverter converter = null) { return(builder.Add(new EnvironmentVariableAdapter(prefix), converter)); }
/// <inheritdoc /> public Dictionary <string, List <object> > GetValues(Predicate <string> predicate, Type type) { if (predicate == null) { throw new ArgumentNullException(nameof(predicate)); } if (type == null) { throw new ArgumentNullException(nameof(type)); } ISettingConverter converter = this.GetConverterForType(type); if (converter == null) { throw new InvalidOperationException($"No converter found for type {type.Name}"); } Dictionary <string, List <string> > stringValues = this.GetRawValues(predicate); Dictionary <string, List <object> > finalValues = new Dictionary <string, List <object> >(SettingService.NameComparer); foreach (KeyValuePair <string, List <string> > stringValue in stringValues) { finalValues.Add(stringValue.Key, new List <object>(stringValue.Value.Select(x => this.ConvertTo(converter, type, x)))); } return(finalValues); }
public SqlServer(string nameOrConnectionString, ISettingConverter converter) : base(new SettingNameFactory(), converter) { ConnectionString = ConnectionStringRepository.Default.GetConnectionString(nameOrConnectionString); SettingTableName = (DefaultSchema, DefaultTable); ColumnMapping = new SqlServerColumnMapping(); }
/// <summary> /// Initializes a new instance of the <see cref="SettingsServiceBuilder"/> class. /// </summary> public SettingsServiceBuilder() { this.appKeyPrefix = string.Empty; this.settingsPostfix = "Settings"; this.converter = new DefaultSettingConverter(); this.handler = new ThrowOnInvalidSettingHandler(); }
/// <inheritdoc /> public List <object> GetValues(string name, Type type) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("The string is empty.", nameof(name)); } if (type == null) { throw new ArgumentNullException(nameof(type)); } ISettingConverter converter = this.GetConverterForType(type); if (converter == null) { throw new InvalidOperationException($"No converter found for type {type.Name}"); } List <string> stringValues = this.GetRawValues(name); List <object> finalValues = stringValues.Select(x => this.ConvertTo(converter, type, x)) .ToList(); return(finalValues); }
public static ISettingsBuilder AddReadOnlyRegistryAdapter( this ISettingsBuilder builder, string root, ISettingConverter converter = null) { return(builder.AddReadOnly(new RegistryAdapter(root), converter)); }
public static ISettingsBuilder LoadFromObject <T>( this ISettingsBuilder builder, T data, ISettingConverter converter = null) { return(builder.Load(new ObjectLoader <T>(data), converter)); }
public ISettingsBuilder Add(ISettingsAdapter adapter, ISettingConverter converter) { converter = converter ?? new DefaultSettingConverter(); var interceptor = new SettingsInterceptor(adapter, converter); _interceptors.Add(interceptor); return(this); }
public static ISettingsBuilder LoadFromCommandLine( this ISettingsBuilder builder, IEnumerable <string> args, IDictionary <string, string> switchMappings = null, ISettingConverter converter = null) { return(builder.Load(new CommandLineLoader(args, switchMappings), converter)); }
/// <summary> /// Initializes a new instance of the <see cref="AspNetCoreSettingsService"/> class. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="appKeyPrefix">The application key prefix.</param> /// <param name="settingsPostfix">The settings postfix.</param> /// <param name="converter">The converter.</param> /// <param name="handler">The handler.</param> public AspNetCoreSettingsService( IConfiguration configuration, string appKeyPrefix = "", string settingsPostfix = "Settings", ISettingConverter converter = null, IInvalidSettingHandler handler = null) : base(new AspNetCoreSettingsSource(configuration), appKeyPrefix, settingsPostfix, converter, handler) { }
/// <summary> /// Initializes a new instance of the <see cref="AppConfigSettingsService"/> class. /// </summary> /// <param name="settings">The settings.</param> /// <param name="appKeyPrefix">The application key prefix.</param> /// <param name="settingsPostfix">The settings postfix.</param> /// <param name="converter">The converter.</param> /// <param name="handler">The handler.</param> public AppConfigSettingsService( NameValueCollection settings, string appKeyPrefix = "", string settingsPostfix = "Settings", ISettingConverter converter = null, IInvalidSettingHandler handler = null) : base(new AppConfigSettingsSource(settings), appKeyPrefix, settingsPostfix, converter, handler) { }
private string convertForSerialization(ISetting setting) { ISettingConverter settingConverter = getConverterForSetting(setting); if (settingConverter != null) { return(settingConverter.Serialize(setting)); } ISettingValueConverter valueConverter = getConverterForSettingValue(setting); if (valueConverter != null) { return(valueConverter.Serialize(setting.ObjValue)); } return(setting.ObjValue?.ToString()); }
private string ConvertFrom(ISettingConverter converter, Type type, object value) { Type usedType = this.GetConverterType(type); bool nullable = this.IsNullable(type); if (nullable && (value == null)) { return(string.Empty); } if (value == null) { return(null); } return(converter.ConvertFrom(usedType, value)); }
private object ConvertTo(ISettingConverter converter, Type type, string value) { Type usedType = this.GetConverterType(type); bool nullable = this.IsNullable(type); if (value == null) { return(null); } if (nullable && string.IsNullOrEmpty(value)) { return(null); } return(converter.ConvertTo(usedType, value)); }
/// <inheritdoc /> public void RemoveConverter(ISettingConverter settingConverter) { if (settingConverter == null) { throw new ArgumentNullException(nameof(settingConverter)); } if (!this.Converters.Contains(settingConverter)) { return; } Trace.TraceInformation($"Removing setting converter: {settingConverter.GetType().Name}"); this.Cache.Clear(); this.Converters.Remove(settingConverter); }
private void convertForDeserialization(ISetting setting, string serialized) { ISettingConverter settingConverter = getConverterForSetting(setting); if (settingConverter != null) { settingConverter.Deserialize(setting, serialized); return; } ISettingValueConverter valueConverter = getConverterForSettingValue(setting); if (valueConverter != null) { setting.ObjValue = valueConverter.Deserialize(serialized); return; } setting.ObjValue = serialized; }
/// <summary> /// Initializes a new instance of the <see cref="DefaultSettingsService"/> class. /// </summary> /// <param name="source">The source.</param> /// <param name="appKeyPrefix">The application key prefix.</param> /// <param name="settingsPostfix">The settings postfix.</param> /// <param name="converter">The converter.</param> /// <param name="handler">The handler.</param> public DefaultSettingsService( ISettingsSource source, string appKeyPrefix = "", string settingsPostfix = "Settings", ISettingConverter converter = null, IInvalidSettingHandler handler = null) { if (string.IsNullOrWhiteSpace(settingsPostfix)) { throw new ArgumentNullException(nameof(settingsPostfix)); } this.appKeyPrefix = appKeyPrefix; this.settingsPostfix = settingsPostfix; this.source = source ?? throw new ArgumentNullException(nameof(source)); this.converter = converter ?? new DefaultSettingConverter(); this.handler = handler ?? new ThrowOnInvalidSettingHandler(); }
/// <inheritdoc /> public void SetValues(string name, IEnumerable values, Type type) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("The string is empty.", nameof(name)); } if (type == null) { throw new ArgumentNullException(nameof(type)); } ISettingConverter converter = this.GetConverterForType(type); if (converter == null) { throw new InvalidOperationException($"No converter found for type {type.Name}"); } if (values == null) { this.DeleteValues(name); return; } List <string> finalValues = values.Cast <object>() .Select(x => this.ConvertFrom(converter, type, x)) .ToList(); if (finalValues.Count == 0) { this.DeleteValues(name); return; } this.SetRawValues(name, finalValues); }
protected SettingProvider([NotNull] ISettingNameFactory settingNameFactory, [NotNull] ISettingConverter converter) : this() { _converter = converter ?? throw new ArgumentNullException(nameof(converter)); _settingNameFactory = settingNameFactory ?? throw new ArgumentNullException(nameof(settingNameFactory)); }
public ISettingsBuilder Load(ISettingsLoader loader, ISettingConverter converter) { var data = loader.Load(); return(AddReadOnly(new MemoryAdapter(data), converter)); }
public ISettingsBuilder AddReadOnly(ISettingsAdapter adapter, ISettingConverter converter) { var readOnlyAdapter = new ReadOnlyAdapter(adapter); return(Add(readOnlyAdapter, converter)); }
public static ExpressionLoaderSettingsBuilder <TMapper> StartMapping <TMapper>( this ISettingsBuilder builder, ISettingConverter converter = null) { return(new ExpressionLoaderSettingsBuilder <TMapper>(builder, converter)); }
public AppSettings(ISettingConverter converter) : base(new SettingNameFactory(), converter) { }
public ISettingsBuilder AddReadOnly(ISettingsAdapter adapter, ISettingConverter converter) { _builder.Load(_expressionLoader, _converter); return(_builder.AddReadOnly(adapter, converter)); }
public ISettingsBuilder Load(ISettingsLoader loader, ISettingConverter converter) { _builder.Load(_expressionLoader, _converter); return(_builder.Load(loader, converter)); }
private Type getTypeForSettingConverter(ISettingConverter converter) => converter.GetType().GetAttribute <SettingConverterAttribute>()?.Type;
public ExpressionLoaderSettingsBuilder(ISettingsBuilder builder, ISettingConverter converter) { _builder = builder; _expressionLoader = new ExpressionLoader <TMapper>(); _converter = converter; }
public SettingsInterceptor(ISettingsAdapter adapter, ISettingConverter converter) { _adapter = adapter; _converter = converter; }