Skip to content

Commit 686df5e

Browse files
committed
Added asserts.
1 parent 3dc0926 commit 686df5e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/Shared/Configuration/OpenTelemetryConfigurationExtensions.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#nullable enable
55

6+
using System.Diagnostics;
67
#if !NETFRAMEWORK && !NETSTANDARD2_0
78
using System.Diagnostics.CodeAnalysis;
89
#endif
@@ -27,7 +28,9 @@ public static bool TryGetStringValue(
2728
#endif
2829
out string? value)
2930
{
30-
value = configuration[key];
31+
Debug.Assert(configuration != null, "configuration was null");
32+
33+
value = configuration![key];
3134

3235
return !string.IsNullOrWhiteSpace(value);
3336
}
@@ -41,6 +44,8 @@ public static bool TryGetUriValue(
4144
#endif
4245
out Uri? value)
4346
{
47+
Debug.Assert(logger != null, "logger was null");
48+
4449
if (!configuration.TryGetStringValue(key, out var stringValue))
4550
{
4651
value = null;
@@ -49,7 +54,7 @@ public static bool TryGetUriValue(
4954

5055
if (!Uri.TryCreate(stringValue, UriKind.Absolute, out value))
5156
{
52-
logger.LogInvalidConfigurationValue(key, stringValue!);
57+
logger!.LogInvalidConfigurationValue(key, stringValue!);
5358
return false;
5459
}
5560

@@ -62,6 +67,8 @@ public static bool TryGetIntValue(
6267
string key,
6368
out int value)
6469
{
70+
Debug.Assert(logger != null, "logger was null");
71+
6572
if (!configuration.TryGetStringValue(key, out var stringValue))
6673
{
6774
value = default;
@@ -70,7 +77,7 @@ public static bool TryGetIntValue(
7077

7178
if (!int.TryParse(stringValue, NumberStyles.None, CultureInfo.InvariantCulture, out value))
7279
{
73-
logger.LogInvalidConfigurationValue(key, stringValue!);
80+
logger!.LogInvalidConfigurationValue(key, stringValue!);
7481
return false;
7582
}
7683

@@ -83,6 +90,8 @@ public static bool TryGetBoolValue(
8390
string key,
8491
out bool value)
8592
{
93+
Debug.Assert(logger != null, "logger was null");
94+
8695
if (!configuration.TryGetStringValue(key, out var stringValue))
8796
{
8897
value = default;
@@ -91,7 +100,7 @@ public static bool TryGetBoolValue(
91100

92101
if (!bool.TryParse(stringValue, out value))
93102
{
94-
logger.LogInvalidConfigurationValue(key, stringValue!);
103+
logger!.LogInvalidConfigurationValue(key, stringValue!);
95104
return false;
96105
}
97106

@@ -108,6 +117,8 @@ public static bool TryGetValue<T>(
108117
#endif
109118
out T? value)
110119
{
120+
Debug.Assert(logger != null, "logger was null");
121+
111122
if (!configuration.TryGetStringValue(key, out var stringValue))
112123
{
113124
value = default;
@@ -116,7 +127,7 @@ public static bool TryGetValue<T>(
116127

117128
if (!tryParseFunc(stringValue!, out value))
118129
{
119-
logger.LogInvalidConfigurationValue(key, stringValue!);
130+
logger!.LogInvalidConfigurationValue(key, stringValue!);
120131
return false;
121132
}
122133

0 commit comments

Comments
 (0)