@@ -87,10 +87,11 @@ public static string TryNormalize(string value)
87
87
}
88
88
}
89
89
90
- // Private fields
90
+ #region Private fields
91
91
private bool ? ssl ;
92
92
private Proxy ? proxy ;
93
93
private RetryStrategy ? reconnectRetryPolicy ;
94
+ #endregion
94
95
95
96
/// <summary>
96
97
/// Gets or sets whether connect/configuration timeouts should be explicitly notified via a TimeoutException.
@@ -468,10 +469,10 @@ private ConfigurationOptions DoParse(string configuration, bool ignoreUnknown =
468
469
ResponseTimeout = OptionKeys . ParseInt32 ( key , value ) ;
469
470
break ;
470
471
case OptionKeys . ReadFrom :
471
- tempReadFromStrategy = ParseReadFromStrategy ( value ) ;
472
+ tempReadFromStrategy = CheckReadFromValue ( value ) ;
472
473
break ;
473
474
case OptionKeys . Az :
474
- tempAz = ParseAzParameter ( value ) ;
475
+ tempAz = CheckAzValue ( value ) ;
475
476
break ;
476
477
default :
477
478
if ( ! ignoreUnknown ) throw new ArgumentException ( $ "Keyword '{ key } ' is not supported.", key ) ;
@@ -496,53 +497,44 @@ private ConfigurationOptions DoParse(string configuration, bool ignoreUnknown =
496
497
return this ;
497
498
}
498
499
499
- private string ParseAzParameter ( string value )
500
+ private string CheckAzValue ( string az )
500
501
{
501
- if ( string . IsNullOrWhiteSpace ( value ) )
502
+ if ( string . IsNullOrWhiteSpace ( az ) )
502
503
{
503
504
throw new ArgumentException ( "Availability zone cannot be empty or whitespace" ) ;
504
505
}
505
- return value ;
506
+ return az ;
506
507
}
507
508
508
509
private ReadFrom ? SetReadFrom ( ReadFromStrategy ? strategy , string ? az )
509
510
{
510
511
if ( strategy . HasValue )
511
512
{
512
513
// Use ReadFrom constructors based on strategy type - the constructors contain the validation logic
513
- #pragma warning disable IDE0066
514
- switch ( strategy . Value )
514
+ return strategy . Value switch
515
515
{
516
- case ReadFromStrategy . AzAffinity :
517
- case ReadFromStrategy . AzAffinityReplicasAndPrimary :
518
- return new ReadFrom ( strategy . Value , az ! ) ;
519
-
520
- case ReadFromStrategy . Primary :
521
- case ReadFromStrategy . PreferReplica :
522
- return new ReadFrom ( strategy . Value ) ;
523
-
524
- default :
525
- throw new ArgumentException ( $ "ReadFrom strategy '{ strategy . Value } ' is not supported. Valid strategies are: Primary, PreferReplica, AzAffinity, AzAffinityReplicasAndPrimary") ;
526
- }
527
- #pragma warning restore IDE0066
516
+ ReadFromStrategy . AzAffinity or ReadFromStrategy . AzAffinityReplicasAndPrimary => new ReadFrom ( strategy . Value , az ! ) ,
517
+ ReadFromStrategy . Primary or ReadFromStrategy . PreferReplica => new ReadFrom ( strategy . Value ) ,
518
+ _ => throw new ArgumentException ( $ "ReadFrom strategy '{ strategy . Value } ' is not supported. Valid strategies are: Primary, PreferReplica, AzAffinity, AzAffinityReplicasAndPrimary") ,
519
+ } ;
528
520
}
529
521
return null ;
530
522
}
531
523
532
- private ReadFromStrategy ParseReadFromStrategy ( string value )
524
+ private ReadFromStrategy CheckReadFromValue ( string readFrom )
533
525
{
534
- if ( string . IsNullOrWhiteSpace ( value ) )
526
+ if ( string . IsNullOrWhiteSpace ( readFrom ) )
535
527
{
536
528
throw new ArgumentException ( "ReadFrom strategy cannot be empty" ) ;
537
529
}
538
530
539
531
try
540
532
{
541
- return Enum . Parse < ReadFromStrategy > ( value , ignoreCase : true ) ;
533
+ return Enum . Parse < ReadFromStrategy > ( readFrom , ignoreCase : true ) ;
542
534
}
543
535
catch ( ArgumentException )
544
536
{
545
- throw new ArgumentException ( $ "ReadFrom strategy '{ value } ' is not supported. Valid strategies are: Primary, PreferReplica, AzAffinity, AzAffinityReplicasAndPrimary") ;
537
+ throw new ArgumentException ( $ "ReadFrom strategy '{ readFrom } ' is not supported. Valid strategies are: Primary, PreferReplica, AzAffinity, AzAffinityReplicasAndPrimary") ;
546
538
}
547
539
}
548
540
0 commit comments