示例#1
0
 private static HashSet <T> GetHashSet <T>(string value, ConfigValuesSplitInfo info)
 {
     if (info == null)
     {
         info = new ConfigValuesSplitInfo
         {
             ConvertValuesToLower = true
         };
     }
     return(new HashSet <T>(value.Split(info.EntrySeperators).Select(v => info.ParseValue <T>(v))));
 }
示例#2
0
 /// <summary>
 /// Attempts to read the setting from the config file and Parse to get the value.
 /// The value from the config if first split by the seperator
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="appSetting"></param>
 /// <param name="defaultValue"></param>
 /// <param name="info"></param>
 /// <returns></returns>
 public static List <T> GetList <T>(string appSetting, string defaultValue, ConfigValuesSplitInfo info = null)
 {
     try
     {
         var config = ConfigProvider.Instance[appSetting] ?? defaultValue;
         return(GetList <T>(config, info));
     }
     catch (Exception ex)
     {
         throw new FormatException($"Error occured parsing list for app setting \"{appSetting}\"", ex);
     }
 }
示例#3
0
 /// <summary>
 /// Attempts to read the setting from the config file and Parse to get the value.
 /// The value from the config if first split by the seperator
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="appSetting"></param>
 /// <param name="defaultValue"></param>
 /// <param name="info"></param>
 /// <returns></returns>
 public static List <T> GetList <T>(string appSetting, List <T> defaultValue, ConfigValuesSplitInfo info = null)
 {
     try
     {
         var config = ConfigurationManager.AppSettings[appSetting];
         return(config == null ? defaultValue : GetList <T>(config, info));
     }
     catch (Exception ex)
     {
         throw new FormatException($"Error occured parsing list for app setting \"{appSetting}\"", ex);
     }
 }
示例#4
0
 /// <summary>
 /// Config Value must be in the format "Value|Value|Value" by Default
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="appSetting"></param>
 /// <param name="defaultValue"></param>
 /// <param name="info">The settings by which to split the config value.</param>
 /// <returns></returns>
 public static HashSet <T> GetHashSet <T>(string appSetting, HashSet <T> defaultValue, ConfigValuesSplitInfo info = null)
 {
     try
     {
         var config = ConfigProvider.Instance[appSetting];
         if (config == null)
         {
             return(defaultValue);
         }
         return(GetHashSet <T>(config, info));
     }
     catch (Exception ex)
     {
         throw new FormatException($"Error occured parsing hash for app setting \"{appSetting}\"", ex);
     }
 }
示例#5
0
 private static List <T> GetList <T>(string value, ConfigValuesSplitInfo info)
 {
     info = info ?? ConfigValuesSplitInfo.Default;
     return(new List <T>(value.Split(info.EntrySeperators, StringSplitOptions.RemoveEmptyEntries).Select(v => info.ParseValue <T>(v))));
 }
示例#6
0
 /// <summary>
 /// Config Value must be in the format "Value|Value|Value" by Default
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="appSetting"></param>
 /// <param name="defaultValue"></param>
 /// <param name="info">The settings by which to split the config value.</param>
 /// <returns></returns>
 public static HashSet <T> GetHashSet <T>(string appSetting, string defaultValue, ConfigValuesSplitInfo info = null)
 {
     try
     {
         return(GetHashSet <T>(ConfigurationManager.AppSettings[appSetting] ?? defaultValue, info));
     }
     catch (Exception ex)
     {
         throw new FormatException($"Error occured parsing hash for app setting \"{appSetting}\"", ex);
     }
 }
示例#7
0
 /// <summary>
 /// Config Value must be in the format "Value|Value|Value" by Default
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="appSetting">The application setting.</param>
 /// <param name="getDefault">The get default.</param>
 /// <param name="info">The information.</param>
 /// <returns></returns>
 /// <exception cref="System.FormatException"></exception>
 public static HashSet <T> GetHashSet <T>(string appSetting, Func <HashSet <T> > getDefault, ConfigValuesSplitInfo info = null)
 {
     try
     {
         var config = ConfigurationManager.AppSettings[appSetting];
         if (config != null)
         {
             return(GetHashSet <T>(config, info));
         }
         return(getDefault());
     }
     catch (Exception ex)
     {
         throw new FormatException($"Error occured parsing hash for app setting \"{appSetting}\"", ex);
     }
 }