コード例 #1
0
 /// <summary>
 /// Gets the setting parser either registered for the type or in the type.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="registry"></param>
 /// <param name="source"></param>
 /// <param name="parsableFirst"></param>
 /// <returns></returns>
 public static ISettingParser GetSettingParser <T>(this StaticSettingParserRegistry registry, T source, bool parsableFirst = true) where T : class
 {
     if (parsableFirst)
     {
         if (source is IParsable parsable)
         {
             return(parsable.SettingParser);
         }
         if (registry.TryRetrieve <T>(out var value))
         {
             return(value);
         }
     }
     else
     {
         if (registry.TryRetrieve <T>(out var value))
         {
             return(value);
         }
         if (source is IParsable parsable)
         {
             return(parsable.SettingParser);
         }
     }
     throw new KeyNotFoundException($"There is no setting parser registered for {typeof(T).Name}.");
 }
コード例 #2
0
 /// <summary>
 /// If <paramref name="source"/> is <see cref="IParsable"/> will use that parser, otherwise searches for a registered parser.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="registry"></param>
 /// <param name="source"></param>
 /// <param name="args"></param>
 /// <param name="parsableFirst">Whether to check for the object being parsable first before trying to get the registered setting parser.</param>
 /// <returns></returns>
 public static ISettingParserResult Parse <T>(this StaticSettingParserRegistry registry, T source, ParseArgs args, bool parsableFirst = true) where T : class
 => registry.GetSettingParser(source, parsableFirst).Parse(source, args);