@@ -468,61 +468,46 @@ public ClassConfigurationResultWithKey<IDictionary<string, string>> AsDictionary
468468 => new ( Telemetry , Key , recordValue : true , configurationResult : GetDictionaryResult ( parser ) ) ;
469469
470470 private ConfigurationResult < string > GetStringResult ( Func < string , bool > ? validator , Func < string , ParsingResult < string > > ? converter , bool recordValue )
471- => converter is null
472- ? GetResult ( Selectors . AsString , validator , recordValue )
473- : GetResult ( Selectors . AsStringWithConverter , validator , converter , recordValue ) ;
471+ {
472+ var source = Source ;
473+ var telemetry = Telemetry ;
474+ return converter is null
475+ ? GetResultWithFallback ( key => source . GetString ( key , telemetry , validator , recordValue ) )
476+ : GetResultWithFallback ( key => source . GetAs ( key , telemetry , converter , validator , recordValue ) ) ;
477+ }
474478
475479 private ConfigurationResult < bool > GetBoolResult ( Func < bool , bool > ? validator , Func < string , ParsingResult < bool > > ? converter )
476- => converter is null
477- ? GetResult ( Selectors . AsBool , validator , recordValue : true )
478- : GetResult ( Selectors . AsBoolWithConverter , validator , converter , recordValue : true ) ;
480+ {
481+ var source = Source ;
482+ var telemetry = Telemetry ;
483+ return converter is null
484+ ? GetResultWithFallback ( key => source . GetBool ( key , telemetry , validator ) )
485+ : GetResultWithFallback ( key => source . GetAs ( key , telemetry , converter , validator , recordValue : true ) ) ;
486+ }
479487
480488 private ConfigurationResult < int > GetInt32Result ( Func < int , bool > ? validator , Func < string , ParsingResult < int > > ? converter )
481- => converter is null
482- ? GetResult ( Selectors . AsInt32 , validator , recordValue : true )
483- : GetResult ( Selectors . AsInt32WithConverter , validator , converter , recordValue : true ) ;
489+ {
490+ var source = Source ;
491+ var telemetry = Telemetry ;
492+ return converter is null
493+ ? GetResultWithFallback ( key => source . GetInt32 ( key , telemetry , validator ) )
494+ : GetResultWithFallback ( key => source . GetAs ( key , telemetry , converter , validator , recordValue : true ) ) ;
495+ }
484496
485497 private ConfigurationResult < double > GetDoubleResult ( Func < double , bool > ? validator , Func < string , ParsingResult < double > > ? converter )
486- => converter is null
487- ? GetResult ( Selectors . AsDouble , validator , recordValue : true )
488- : GetResult ( Selectors . AsDoubleWithConverter , validator , converter , recordValue : true ) ;
489-
490- private ConfigurationResult < T > GetAs < T > ( Func < T , bool > ? validator , Func < string , ParsingResult < T > > converter )
491- => GetResult (
492- ( source , key , telemetry , val , convert , recordValue ) => source . GetAs ( key , telemetry , convert ! , val , recordValue ) ,
493- validator ,
494- converter ,
495- recordValue : true ) ;
496-
497- /// <summary>
498- /// Gets the raw <see cref="ConfigurationResult{T}"/> from the configuration source, recording the access in telemetry
499- /// </summary>
500- /// <param name="selector">The method to invoke to retrieve the parameter</param>
501- /// <param name="validator">The validator to call to decide if a provided value is valid</param>
502- /// <param name="recordValue">If applicable, whether to record the value in configuration</param>
503- /// <typeparam name="T">The type being retrieved</typeparam>
504- /// <returns>The raw <see cref="ConfigurationResult{T}"/></returns>
505- private ConfigurationResult < T > GetResult < T > ( Func < IConfigurationSource , string , IConfigurationTelemetry , Func < T , bool > ? , bool , ConfigurationResult < T > > selector , Func < T , bool > ? validator , bool recordValue )
506498 {
507499 var source = Source ;
508500 var telemetry = Telemetry ;
509- return GetResultWithFallback ( key => selector ( source , key , telemetry , validator , recordValue ) ) ;
501+ return converter is null
502+ ? GetResultWithFallback ( key => source . GetDouble ( key , telemetry , validator ) )
503+ : GetResultWithFallback ( key => source . GetAs ( key , telemetry , converter , validator , recordValue : true ) ) ;
510504 }
511505
512- /// <summary>
513- /// Gets the raw <see cref="ConfigurationResult{T}"/> from the configuration source, recording the access in telemetry
514- /// </summary>
515- /// <param name="selector">The method to invoke to retrieve the parameter</param>
516- /// <param name="validator">The validator to call to decide if a provided value is valid</param>
517- /// <param name="converter">The converter to run when calling <see cref="IConfigurationSource.GetAs{T}"/></param>
518- /// <param name="recordValue">If applicable, whether to record the value in configuration</param>
519- /// <typeparam name="T">The type being retrieved</typeparam>
520- /// <returns>The raw <see cref="ConfigurationResult{T}"/></returns>
521- private ConfigurationResult < T > GetResult < T > ( Func < IConfigurationSource , string , IConfigurationTelemetry , Func < T , bool > ? , Func < string , ParsingResult < T > > , bool , ConfigurationResult < T > > selector , Func < T , bool > ? validator , Func < string , ParsingResult < T > > converter , bool recordValue )
506+ private ConfigurationResult < T > GetAs < T > ( Func < T , bool > ? validator , Func < string , ParsingResult < T > > converter )
522507 {
523508 var source = Source ;
524509 var telemetry = Telemetry ;
525- return GetResultWithFallback ( key => selector ( source , key , telemetry , validator , converter , recordValue ) ) ;
510+ return GetResultWithFallback ( key => source . GetAs ( key , telemetry , converter , validator , recordValue : true ) ) ;
526511 }
527512
528513 private ConfigurationResult < IDictionary < string , string > > GetDictionaryResult ( bool allowOptionalMappings , char separator )
@@ -553,7 +538,7 @@ private ConfigurationResult<T> GetResultWithFallback<T>(Func<string, Configurati
553538 return result ;
554539 }
555540
556- string [ ] aliases = _providedAliases ?? ConfigKeyAliasesSwitcher . GetAliases ( Key ) ;
541+ var aliases = _providedAliases ?? ConfigKeyAliasesSwitcher . GetAliases ( Key ) ;
557542
558543 foreach ( var alias in aliases )
559544 {
@@ -725,33 +710,4 @@ public T OverrideWith(in ClassConfigurationResultWithKey<T> otelConfig, IConfigu
725710 return defaultValue . Value . Result ;
726711 }
727712 }
728-
729- private static class Selectors
730- {
731- // static accessor functions
732- internal static readonly Func < IConfigurationSource , string , IConfigurationTelemetry , Func < string , bool > ? , bool , ConfigurationResult < string > > AsString
733- = ( source , key , telemetry , validator , recordValue ) => source . GetString ( key , telemetry , validator , recordValue ) ;
734-
735- internal static readonly Func < IConfigurationSource , string , IConfigurationTelemetry , Func < bool , bool > ? , bool , ConfigurationResult < bool > > AsBool
736- = ( source , key , telemetry , validator , _ ) => source . GetBool ( key , telemetry , validator ) ;
737-
738- internal static readonly Func < IConfigurationSource , string , IConfigurationTelemetry , Func < int , bool > ? , bool , ConfigurationResult < int > > AsInt32
739- = ( source , key , telemetry , validator , _ ) => source . GetInt32 ( key , telemetry , validator ) ;
740-
741- internal static readonly Func < IConfigurationSource , string , IConfigurationTelemetry , Func < double , bool > ? , bool , ConfigurationResult < double > > AsDouble
742- = ( source , key , telemetry , validator , _ ) => source . GetDouble ( key , telemetry , validator ) ;
743-
744- // static accessor functions with converters
745- internal static readonly Func < IConfigurationSource , string , IConfigurationTelemetry , Func < string , bool > ? , Func < string , ParsingResult < string > > , bool , ConfigurationResult < string > > AsStringWithConverter
746- = ( source , key , telemetry , validator , converter , recordValue ) => source . GetAs ( key , telemetry , converter , validator , recordValue ) ;
747-
748- internal static readonly Func < IConfigurationSource , string , IConfigurationTelemetry , Func < bool , bool > ? , Func < string , ParsingResult < bool > > , bool , ConfigurationResult < bool > > AsBoolWithConverter
749- = ( source , key , telemetry , validator , converter , _ ) => source . GetAs ( key , telemetry , converter , validator , recordValue : true ) ;
750-
751- internal static readonly Func < IConfigurationSource , string , IConfigurationTelemetry , Func < int , bool > ? , Func < string , ParsingResult < int > > , bool , ConfigurationResult < int > > AsInt32WithConverter
752- = ( source , key , telemetry , validator , converter , _ ) => source . GetAs ( key , telemetry , converter , validator , recordValue : true ) ;
753-
754- internal static readonly Func < IConfigurationSource , string , IConfigurationTelemetry , Func < double , bool > ? , Func < string , ParsingResult < double > > , bool , ConfigurationResult < double > > AsDoubleWithConverter
755- = ( source , key , telemetry , validator , converter , _ ) => source . GetAs ( key , telemetry , converter , validator , recordValue : true ) ;
756- }
757713}
0 commit comments