@@ -252,21 +252,39 @@ public T GetAs<T>(Func<DefaultResult<T>> getDefaultValue, Func<T, bool>? validat
252
252
// ****************
253
253
// Bool accessors
254
254
// ****************
255
- public bool ? AsBool ( ) => AsBool ( getDefaultValue : null , validator : null ) ;
255
+ public bool ? AsBool ( ) => AsBool ( defaultValue : null , validator : null , converter : null ) ;
256
256
257
257
public bool AsBool ( bool defaultValue ) => AsBool ( ( ) => defaultValue , validator : null ) . Value ;
258
258
259
- public bool ? AsBool ( Func < bool , bool > validator ) => AsBool ( null , validator ) ;
259
+ public bool ? AsBool ( Func < bool , bool > validator ) => AsBool ( defaultValue : null , validator , converter : null ) ;
260
260
261
261
public bool AsBool ( bool defaultValue , Func < bool , bool > ? validator )
262
- => AsBool ( ( ) => defaultValue , validator ) . Value ;
262
+ => AsBool ( defaultValue , validator , converter : null ) . Value ;
263
263
264
264
[ return : NotNullIfNotNull ( nameof ( getDefaultValue ) ) ] // This doesn't work with nullables, but it still expresses intent
265
- public bool ? AsBool ( Func < DefaultResult < bool > > ? getDefaultValue , Func < bool , bool > ? validator )
265
+ public bool ? AsBool ( Func < bool > ? getDefaultValue , Func < bool , bool > ? validator )
266
266
=> AsBool ( getDefaultValue , validator , converter : null ) ;
267
267
268
+ [ return : NotNullIfNotNull ( nameof ( defaultValue ) ) ]
269
+ public bool ? AsBool ( bool ? defaultValue , Func < bool , bool > ? validator , Func < string , ParsingResult < bool > > ? converter )
270
+ {
271
+ var result = GetBoolResult ( validator , converter : null ) ;
272
+ if ( result is { Result : { } ddResult , IsValid : true } )
273
+ {
274
+ return ddResult ;
275
+ }
276
+
277
+ if ( defaultValue is not { } value )
278
+ {
279
+ return null ;
280
+ }
281
+
282
+ Telemetry . Record ( Key , value , ConfigurationOrigins . Default ) ;
283
+ return value ;
284
+ }
285
+
268
286
[ return : NotNullIfNotNull ( nameof ( getDefaultValue ) ) ] // This doesn't work with nullables, but it still expresses intent
269
- public bool ? AsBool ( Func < DefaultResult < bool > > ? getDefaultValue , Func < bool , bool > ? validator , Func < string , ParsingResult < bool > > ? converter )
287
+ public bool ? AsBool ( Func < bool > ? getDefaultValue , Func < bool , bool > ? validator , Func < string , ParsingResult < bool > > ? converter )
270
288
{
271
289
var result = GetBoolResult ( validator , converter ) ;
272
290
return TryHandleResult ( Telemetry , Key , result , recordValue : true , getDefaultValue , out var value ) ? value : null ;
0 commit comments