Skip to content

Commit f374830

Browse files
committed
nit: move selectors to nested type (they're confusing to see!)
1 parent 09736c2 commit f374830

File tree

1 file changed

+37
-34
lines changed

1 file changed

+37
-34
lines changed

tracer/src/Datadog.Trace/Configuration/ConfigurationSources/Telemetry/ConfigurationBuilder.cs

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,6 @@ namespace Datadog.Trace.Configuration.Telemetry;
1414

1515
internal readonly struct ConfigurationBuilder
1616
{
17-
// static accessor functions
18-
private static readonly Func<IConfigurationSource, string, IConfigurationTelemetry, Func<string, bool>?, bool, ConfigurationResult<string>> AsStringSelector
19-
= (source, key, telemetry, validator, recordValue) => source.GetString(key, telemetry, validator, recordValue);
20-
21-
private static readonly Func<IConfigurationSource, string, IConfigurationTelemetry, Func<bool, bool>?, bool, ConfigurationResult<bool>> AsBoolSelector
22-
= (source, key, telemetry, validator, _) => source.GetBool(key, telemetry, validator);
23-
24-
private static readonly Func<IConfigurationSource, string, IConfigurationTelemetry, Func<int, bool>?, bool, ConfigurationResult<int>> AsInt32Selector
25-
= (source, key, telemetry, validator, _) => source.GetInt32(key, telemetry, validator);
26-
27-
private static readonly Func<IConfigurationSource, string, IConfigurationTelemetry, Func<double, bool>?, bool, ConfigurationResult<double>> AsDoubleSelector
28-
= (source, key, telemetry, validator, _) => source.GetDouble(key, telemetry, validator);
29-
30-
// static accessor functions with converters
31-
private static readonly Func<IConfigurationSource, string, IConfigurationTelemetry, Func<string, bool>?, Func<string, ParsingResult<string>>, bool, ConfigurationResult<string>> AsStringWithConverterSelector
32-
= (source, key, telemetry, validator, converter, recordValue) => source.GetAs(key, telemetry, converter, validator, recordValue);
33-
34-
private static readonly Func<IConfigurationSource, string, IConfigurationTelemetry, Func<bool, bool>?, Func<string, ParsingResult<bool>>, bool, ConfigurationResult<bool>> AsBoolWithConverterSelector
35-
= (source, key, telemetry, validator, converter, _) => source.GetAs(key, telemetry, converter, validator, recordValue: true);
36-
37-
private static readonly Func<IConfigurationSource, string, IConfigurationTelemetry, Func<int, bool>?, Func<string, ParsingResult<int>>, bool, ConfigurationResult<int>> AsInt32WithConverterSelector
38-
= (source, key, telemetry, validator, converter, _) => source.GetAs(key, telemetry, converter, validator, recordValue: true);
39-
40-
private static readonly Func<IConfigurationSource, string, IConfigurationTelemetry, Func<double, bool>?, Func<string, ParsingResult<double>>, bool, ConfigurationResult<double>> AsDoubleWithConverterSelector
41-
= (source, key, telemetry, validator, converter, _) => source.GetAs(key, telemetry, converter, validator, recordValue: true);
42-
4317
private readonly IConfigurationSource _source;
4418
private readonly IConfigurationTelemetry _telemetry;
4519

@@ -374,23 +348,23 @@ public ClassConfigurationResultWithKey<IDictionary<string, string>> AsDictionary
374348

375349
private ConfigurationResult<string> GetStringResult(Func<string, bool>? validator, Func<string, ParsingResult<string>>? converter, bool recordValue)
376350
=> converter is null
377-
? GetResult(AsStringSelector, validator, recordValue)
378-
: GetResult(AsStringWithConverterSelector, validator, converter, recordValue);
351+
? GetResult(Selectors.AsString, validator, recordValue)
352+
: GetResult(Selectors.AsStringWithConverter, validator, converter, recordValue);
379353

380354
private ConfigurationResult<bool> GetBoolResult(Func<bool, bool>? validator, Func<string, ParsingResult<bool>>? converter)
381355
=> converter is null
382-
? GetResult(AsBoolSelector, validator, recordValue: true)
383-
: GetResult(AsBoolWithConverterSelector, validator, converter, recordValue: true);
356+
? GetResult(Selectors.AsBool, validator, recordValue: true)
357+
: GetResult(Selectors.AsBoolWithConverter, validator, converter, recordValue: true);
384358

385359
private ConfigurationResult<int> GetInt32Result(Func<int, bool>? validator, Func<string, ParsingResult<int>>? converter)
386360
=> converter is null
387-
? GetResult(AsInt32Selector, validator, recordValue: true)
388-
: GetResult(AsInt32WithConverterSelector, validator, converter, recordValue: true);
361+
? GetResult(Selectors.AsInt32, validator, recordValue: true)
362+
: GetResult(Selectors.AsInt32WithConverter, validator, converter, recordValue: true);
389363

390364
private ConfigurationResult<double> GetDoubleResult(Func<double, bool>? validator, Func<string, ParsingResult<double>>? converter)
391365
=> converter is null
392-
? GetResult(AsDoubleSelector, validator, recordValue: true)
393-
: GetResult(AsDoubleWithConverterSelector, validator, converter, recordValue: true);
366+
? GetResult(Selectors.AsDouble, validator, recordValue: true)
367+
: GetResult(Selectors.AsDoubleWithConverter, validator, converter, recordValue: true);
394368

395369
private ConfigurationResult<T> GetAs<T>(Func<T, bool>? validator, Func<string, ParsingResult<T>> converter)
396370
=> GetResult(
@@ -596,4 +570,33 @@ public T OverrideWith(in ClassConfigurationResultWithKey<T> otelConfig, IConfigu
596570
return null;
597571
}
598572
}
573+
574+
private static class Selectors
575+
{
576+
// static accessor functions
577+
internal static readonly Func<IConfigurationSource, string, IConfigurationTelemetry, Func<string, bool>?, bool, ConfigurationResult<string>> AsString
578+
= (source, key, telemetry, validator, recordValue) => source.GetString(key, telemetry, validator, recordValue);
579+
580+
internal static readonly Func<IConfigurationSource, string, IConfigurationTelemetry, Func<bool, bool>?, bool, ConfigurationResult<bool>> AsBool
581+
= (source, key, telemetry, validator, _) => source.GetBool(key, telemetry, validator);
582+
583+
internal static readonly Func<IConfigurationSource, string, IConfigurationTelemetry, Func<int, bool>?, bool, ConfigurationResult<int>> AsInt32
584+
= (source, key, telemetry, validator, _) => source.GetInt32(key, telemetry, validator);
585+
586+
internal static readonly Func<IConfigurationSource, string, IConfigurationTelemetry, Func<double, bool>?, bool, ConfigurationResult<double>> AsDouble
587+
= (source, key, telemetry, validator, _) => source.GetDouble(key, telemetry, validator);
588+
589+
// static accessor functions with converters
590+
internal static readonly Func<IConfigurationSource, string, IConfigurationTelemetry, Func<string, bool>?, Func<string, ParsingResult<string>>, bool, ConfigurationResult<string>> AsStringWithConverter
591+
= (source, key, telemetry, validator, converter, recordValue) => source.GetAs(key, telemetry, converter, validator, recordValue);
592+
593+
internal static readonly Func<IConfigurationSource, string, IConfigurationTelemetry, Func<bool, bool>?, Func<string, ParsingResult<bool>>, bool, ConfigurationResult<bool>> AsBoolWithConverter
594+
= (source, key, telemetry, validator, converter, _) => source.GetAs(key, telemetry, converter, validator, recordValue: true);
595+
596+
internal static readonly Func<IConfigurationSource, string, IConfigurationTelemetry, Func<int, bool>?, Func<string, ParsingResult<int>>, bool, ConfigurationResult<int>> AsInt32WithConverter
597+
= (source, key, telemetry, validator, converter, _) => source.GetAs(key, telemetry, converter, validator, recordValue: true);
598+
599+
internal static readonly Func<IConfigurationSource, string, IConfigurationTelemetry, Func<double, bool>?, Func<string, ParsingResult<double>>, bool, ConfigurationResult<double>> AsDoubleWithConverter
600+
= (source, key, telemetry, validator, converter, _) => source.GetAs(key, telemetry, converter, validator, recordValue: true);
601+
}
599602
}

0 commit comments

Comments
 (0)