using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using Taloyhtio.GeneralApi.Common.Extensions; namespace Taloyhtio.GeneralApi.Core.Services.Impl { public class SettingsProvider : ISettingsProvider { private IConverter converter; public SettingsProvider(IConverter converter) { this.converter = converter; } public T Get(string key) { string val = getVal(key); return this.converter.Convert(val); } public IEnumerable GetArray(string key) { string val = getVal(key); if (string.IsNullOrEmpty(val)) { return new List(); } var vals = val.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries); if (vals.IsNullOrEmpty()) { return new List(); } var converted = vals.Select(c => this.converter.Convert(c)); return converted; } private string getVal(string key) { return ConfigurationManager.AppSettings[key]; } } }