@@ -244,8 +244,7 @@ public int Port
244244 get => _port ;
245245 set
246246 {
247- if ( value <= 0 )
248- throw new ArgumentOutOfRangeException ( nameof ( value ) , value , "Invalid port: " + value ) ;
247+ ArgumentOutOfRangeException . ThrowIfNegativeOrZero ( value ) ;
249248
250249 _port = value ;
251250 SetValue ( nameof ( Port ) , value ) ;
@@ -720,8 +719,7 @@ public int MinPoolSize
720719 get => _minPoolSize ;
721720 set
722721 {
723- if ( value < 0 )
724- throw new ArgumentOutOfRangeException ( nameof ( value ) , value , "MinPoolSize can't be negative" ) ;
722+ ArgumentOutOfRangeException . ThrowIfNegative ( value ) ;
725723
726724 _minPoolSize = value ;
727725 SetValue ( nameof ( MinPoolSize ) , value ) ;
@@ -742,8 +740,7 @@ public int MaxPoolSize
742740 get => _maxPoolSize ;
743741 set
744742 {
745- if ( value < 0 )
746- throw new ArgumentOutOfRangeException ( nameof ( value ) , value , "MaxPoolSize can't be negative" ) ;
743+ ArgumentOutOfRangeException . ThrowIfNegative ( value ) ;
747744
748745 _maxPoolSize = value ;
749746 SetValue ( nameof ( MaxPoolSize ) , value ) ;
@@ -836,8 +833,8 @@ public int Timeout
836833 get => _timeout ;
837834 set
838835 {
839- if ( value < 0 || value > NpgsqlConnection . TimeoutLimit )
840- throw new ArgumentOutOfRangeException ( nameof ( value ) , value , "Timeout must be between 0 and " + NpgsqlConnection . TimeoutLimit ) ;
836+ ArgumentOutOfRangeException . ThrowIfNegative ( value ) ;
837+ ArgumentOutOfRangeException . ThrowIfGreaterThan ( value , NpgsqlConnection . TimeoutLimit ) ;
841838
842839 _timeout = value ;
843840 SetValue ( nameof ( Timeout ) , value ) ;
@@ -861,8 +858,7 @@ public int CommandTimeout
861858 get => _commandTimeout ;
862859 set
863860 {
864- if ( value < 0 )
865- throw new ArgumentOutOfRangeException ( nameof ( value ) , value , "CommandTimeout can't be negative" ) ;
861+ ArgumentOutOfRangeException . ThrowIfNegative ( value ) ;
866862
867863 _commandTimeout = value ;
868864 SetValue ( nameof ( CommandTimeout ) , value ) ;
@@ -885,8 +881,7 @@ public int CancellationTimeout
885881 get => _cancellationTimeout ;
886882 set
887883 {
888- if ( value < - 1 )
889- throw new ArgumentOutOfRangeException ( nameof ( value ) , value , $ "{ nameof ( CancellationTimeout ) } can't less than -1") ;
884+ ArgumentOutOfRangeException . ThrowIfLessThan ( value , - 1 ) ;
890885
891886 _cancellationTimeout = value ;
892887 SetValue ( nameof ( CancellationTimeout ) , value ) ;
@@ -975,8 +970,7 @@ public int HostRecheckSeconds
975970 get => _hostRecheckSeconds ;
976971 set
977972 {
978- if ( value < 0 )
979- throw new ArgumentException ( $ "{ HostRecheckSeconds } cannot be negative", nameof ( HostRecheckSeconds ) ) ;
973+ ArgumentOutOfRangeException . ThrowIfNegative ( value ) ;
980974 _hostRecheckSeconds = value ;
981975 SetValue ( nameof ( HostRecheckSeconds ) , value ) ;
982976 }
@@ -1000,8 +994,7 @@ public int KeepAlive
1000994 get => _keepAlive ;
1001995 set
1002996 {
1003- if ( value < 0 )
1004- throw new ArgumentOutOfRangeException ( nameof ( value ) , value , "KeepAlive can't be negative" ) ;
997+ ArgumentOutOfRangeException . ThrowIfNegative ( value ) ;
1005998
1006999 _keepAlive = value ;
10071000 SetValue ( nameof ( KeepAlive ) , value ) ;
@@ -1041,8 +1034,7 @@ public int TcpKeepAliveTime
10411034 get => _tcpKeepAliveTime ;
10421035 set
10431036 {
1044- if ( value < 0 )
1045- throw new ArgumentOutOfRangeException ( nameof ( value ) , value , "TcpKeepAliveTime can't be negative" ) ;
1037+ ArgumentOutOfRangeException . ThrowIfNegative ( value ) ;
10461038
10471039 _tcpKeepAliveTime = value ;
10481040 SetValue ( nameof ( TcpKeepAliveTime ) , value ) ;
@@ -1063,8 +1055,7 @@ public int TcpKeepAliveInterval
10631055 get => _tcpKeepAliveInterval ;
10641056 set
10651057 {
1066- if ( value < 0 )
1067- throw new ArgumentOutOfRangeException ( nameof ( value ) , value , "TcpKeepAliveInterval can't be negative" ) ;
1058+ ArgumentOutOfRangeException . ThrowIfNegative ( value ) ;
10681059
10691060 _tcpKeepAliveInterval = value ;
10701061 SetValue ( nameof ( TcpKeepAliveInterval ) , value ) ;
@@ -1160,8 +1151,7 @@ public int MaxAutoPrepare
11601151 get => _maxAutoPrepare ;
11611152 set
11621153 {
1163- if ( value < 0 )
1164- throw new ArgumentOutOfRangeException ( nameof ( value ) , value , $ "{ nameof ( MaxAutoPrepare ) } cannot be negative") ;
1154+ ArgumentOutOfRangeException . ThrowIfNegative ( value ) ;
11651155
11661156 _maxAutoPrepare = value ;
11671157 SetValue ( nameof ( MaxAutoPrepare ) , value ) ;
@@ -1183,8 +1173,7 @@ public int AutoPrepareMinUsages
11831173 get => _autoPrepareMinUsages ;
11841174 set
11851175 {
1186- if ( value < 1 )
1187- throw new ArgumentOutOfRangeException ( nameof ( value ) , value , $ "{ nameof ( AutoPrepareMinUsages ) } must be 1 or greater") ;
1176+ ArgumentOutOfRangeException . ThrowIfNegativeOrZero ( value ) ;
11881177
11891178 _autoPrepareMinUsages = value ;
11901179 SetValue ( nameof ( AutoPrepareMinUsages ) , value ) ;
@@ -1408,8 +1397,7 @@ public int InternalCommandTimeout
14081397
14091398 internal void PostProcessAndValidate ( )
14101399 {
1411- if ( string . IsNullOrWhiteSpace ( Host ) )
1412- throw new ArgumentException ( "Host can't be null" ) ;
1400+ ArgumentException . ThrowIfNullOrWhiteSpace ( Host ) ;
14131401 if ( Multiplexing && ! Pooling )
14141402 throw new ArgumentException ( "Pooling must be on to use multiplexing" ) ;
14151403 if ( SslNegotiation == SslNegotiation . Direct && SslMode is not SslMode . Require and not SslMode . VerifyCA and not SslMode . VerifyFull )
0 commit comments