<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.4.0" />

AppSettingsReader

public class AppSettingsReader
using System.Collections.Specialized; using System.Globalization; namespace System.Configuration { public class AppSettingsReader { private NameValueCollection _map; private static Type s_stringType = typeof(string); private static Type[] _paramsArray = new Type[1] { s_stringType }; private static string NullString = "None"; public AppSettingsReader() { _map = ConfigurationManager.AppSettings; } public object GetValue(string key, Type type) { if (key == null) throw new ArgumentNullException("key"); if (type == (Type)null) throw new ArgumentNullException("type"); string text = _map[key]; if (text != null) { if (!(type == s_stringType)) try { return Convert.ChangeType(text, type, CultureInfo.InvariantCulture); } catch (Exception) { string arg = (text.Length == 0) ? System.SR.AppSettingsReaderEmptyString : text; throw new InvalidOperationException(string.Format(System.SR.AppSettingsReaderCantParse, arg, key, type.ToString())); } switch (GetNoneNesting(text)) { case 0: return text; case 1: return null; default: return text.Substring(1, text.Length - 2); } } throw new InvalidOperationException(string.Format(System.SR.AppSettingsReaderNoKey, key)); } private int GetNoneNesting(string val) { int i = 0; int length = val.Length; if (length > 1) { for (; val[i] == '(' && val[length - i - 1] == ')'; i++) { } if (i > 0 && string.Compare(NullString, 0, val, i, length - 2 * i, StringComparison.Ordinal) != 0) i = 0; } return i; } } }