Skip to content

Commit 8c26ec4

Browse files
author
rstam
committed
Improved wording of error messages and changed WValue so no new subclasses can be created.
1 parent 740c248 commit 8c26ec4

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

Driver/Core/MongoConnectionStringBuilder.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public TimeSpan ConnectTimeout
168168
{
169169
if (value < TimeSpan.Zero)
170170
{
171-
throw new ArgumentOutOfRangeException("value", "ConnectTimeout must be larger than or equal to zero.");
171+
throw new ArgumentOutOfRangeException("value", "ConnectTimeout must be greater than or equal to zero.");
172172
}
173173
_connectTimeout = value;
174174
base["connectTimeout"] = MongoUrlBuilder.FormatTimeSpan(value);
@@ -271,7 +271,7 @@ public TimeSpan MaxConnectionIdleTime
271271
{
272272
if (value < TimeSpan.Zero)
273273
{
274-
throw new ArgumentOutOfRangeException("value", "MaxConnectionIdleTime must be larger than or equal to zero.");
274+
throw new ArgumentOutOfRangeException("value", "MaxConnectionIdleTime must be greater than or equal to zero.");
275275
}
276276
_maxConnectionIdleTime = value;
277277
base["maxIdleTime"] = MongoUrlBuilder.FormatTimeSpan(value);
@@ -288,7 +288,7 @@ public TimeSpan MaxConnectionLifeTime
288288
{
289289
if (value < TimeSpan.Zero)
290290
{
291-
throw new ArgumentOutOfRangeException("value", "MaxConnectionLifeTime must be larger than or equal to zero.");
291+
throw new ArgumentOutOfRangeException("value", "MaxConnectionLifeTime must be greater than or equal to zero.");
292292
}
293293
_maxConnectionLifeTime = value;
294294
base["maxLifeTime"] = MongoUrlBuilder.FormatTimeSpan(value);
@@ -305,7 +305,7 @@ public int MaxConnectionPoolSize
305305
{
306306
if (value <= 0)
307307
{
308-
throw new ArgumentOutOfRangeException("value", "MaxConnectionPoolSize must be larger than zero.");
308+
throw new ArgumentOutOfRangeException("value", "MaxConnectionPoolSize must be greater than zero.");
309309
}
310310
_maxConnectionPoolSize = value;
311311
base["maxPoolSize"] = XmlConvert.ToString(value);
@@ -320,9 +320,9 @@ public int MinConnectionPoolSize
320320
get { return _minConnectionPoolSize; }
321321
set
322322
{
323-
if (value <= 0)
323+
if (value < 0)
324324
{
325-
throw new ArgumentOutOfRangeException("value", "MinConnectionPoolSize must be larger than zero.");
325+
throw new ArgumentOutOfRangeException("value", "MinConnectionPoolSize must be greater than or equal to zero.");
326326
}
327327
_minConnectionPoolSize = value;
328328
base["minPoolSize"] = XmlConvert.ToString(value);
@@ -476,7 +476,7 @@ public TimeSpan SecondaryAcceptableLatency
476476
{
477477
if (value < TimeSpan.Zero)
478478
{
479-
throw new ArgumentOutOfRangeException("value", "SecondaryAcceptableLatency must be larger than zero.");
479+
throw new ArgumentOutOfRangeException("value", "SecondaryAcceptableLatency must be greater than or equal to zero.");
480480
}
481481
_secondaryAcceptableLatency = value;
482482
base["secondaryAcceptableLatency"] = MongoUrlBuilder.FormatTimeSpan(value);
@@ -547,7 +547,7 @@ public TimeSpan SocketTimeout
547547
{
548548
if (value < TimeSpan.Zero)
549549
{
550-
throw new ArgumentOutOfRangeException("value", "SocketTimeout must be larger than or equal to zero.");
550+
throw new ArgumentOutOfRangeException("value", "SocketTimeout must be greater than or equal to zero.");
551551
}
552552
_socketTimeout = value;
553553
base["socketTimeout"] = MongoUrlBuilder.FormatTimeSpan(value);
@@ -616,7 +616,7 @@ public double WaitQueueMultiple
616616
{
617617
if (value <= 0.0)
618618
{
619-
throw new ArgumentOutOfRangeException("value", "WaitQueueMultiple must be larger than zero.");
619+
throw new ArgumentOutOfRangeException("value", "WaitQueueMultiple must be greater than zero.");
620620
}
621621
_waitQueueMultiple = value;
622622
_waitQueueSize = 0;
@@ -635,7 +635,7 @@ public int WaitQueueSize
635635
{
636636
if (value <= 0)
637637
{
638-
throw new ArgumentOutOfRangeException("value", "WaitQueueSize must be larger than 0.");
638+
throw new ArgumentOutOfRangeException("value", "WaitQueueSize must be greater than zero.");
639639
}
640640
_waitQueueSize = value;
641641
_waitQueueMultiple = 0.0;
@@ -654,7 +654,7 @@ public TimeSpan WaitQueueTimeout
654654
{
655655
if (value < TimeSpan.Zero)
656656
{
657-
throw new ArgumentOutOfRangeException("value", "WaitQueueTimeout must be larger than or equal to zero.");
657+
throw new ArgumentOutOfRangeException("value", "WaitQueueTimeout must be greater than or equal to zero.");
658658
}
659659
_waitQueueTimeout = value;
660660
base["waitQueueTimeout"] = MongoUrlBuilder.FormatTimeSpan(value);
@@ -672,7 +672,7 @@ public TimeSpan? WTimeout
672672
if (value != null) { EnsureFireAndForgetIsNotTrue("WTimeout"); }
673673
if (value != null && value.Value < TimeSpan.Zero)
674674
{
675-
throw new ArgumentOutOfRangeException("value", "WTimeout must be larger than or equal to zero.");
675+
throw new ArgumentOutOfRangeException("value", "WTimeout must be greater than or equal to zero.");
676676
}
677677
_wTimeout = value;
678678
base["wtimeout"] = (value == null) ? null : MongoUrlBuilder.FormatTimeSpan(value.Value);

Driver/Core/MongoUrlBuilder.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public TimeSpan ConnectTimeout
118118
{
119119
if (value < TimeSpan.Zero)
120120
{
121-
throw new ArgumentOutOfRangeException("value", "ConnectTimeout must be larger than or equal to zero.");
121+
throw new ArgumentOutOfRangeException("value", "ConnectTimeout must be greater than or equal to zero.");
122122
}
123123
_connectTimeout = value;
124124
}
@@ -216,7 +216,7 @@ public TimeSpan MaxConnectionIdleTime
216216
{
217217
if (value < TimeSpan.Zero)
218218
{
219-
throw new ArgumentOutOfRangeException("value", "MaxConnectionIdleTime must be larger than or equal to zero.");
219+
throw new ArgumentOutOfRangeException("value", "MaxConnectionIdleTime must be greater than or equal to zero.");
220220
}
221221
_maxConnectionIdleTime = value;
222222
}
@@ -232,7 +232,7 @@ public TimeSpan MaxConnectionLifeTime
232232
{
233233
if (value < TimeSpan.Zero)
234234
{
235-
throw new ArgumentOutOfRangeException("value", "MaxConnectionLifeTime must be larger than or equal to zero.");
235+
throw new ArgumentOutOfRangeException("value", "MaxConnectionLifeTime must be greater than or equal to zero.");
236236
}
237237
_maxConnectionLifeTime = value;
238238
}
@@ -248,7 +248,7 @@ public int MaxConnectionPoolSize
248248
{
249249
if (value <= 0)
250250
{
251-
throw new ArgumentOutOfRangeException("value", "MaxConnectionPoolSize must be larger than zero.");
251+
throw new ArgumentOutOfRangeException("value", "MaxConnectionPoolSize must be greater than zero.");
252252
}
253253
_maxConnectionPoolSize = value;
254254
}
@@ -262,9 +262,9 @@ public int MinConnectionPoolSize
262262
get { return _minConnectionPoolSize; }
263263
set
264264
{
265-
if (value <= 0)
265+
if (value < 0)
266266
{
267-
throw new ArgumentOutOfRangeException("value", "MinConnectionPoolSize must be larger than zero.");
267+
throw new ArgumentOutOfRangeException("value", "MinConnectionPoolSize must be greater than or equal to zero.");
268268
}
269269
_minConnectionPoolSize = value;
270270
}
@@ -384,7 +384,7 @@ public TimeSpan SecondaryAcceptableLatency
384384
{
385385
if (value < TimeSpan.Zero)
386386
{
387-
throw new ArgumentOutOfRangeException("value", "SecondaryAcceptableLatency must be larger than zero.");
387+
throw new ArgumentOutOfRangeException("value", "SecondaryAcceptableLatency must be greater than or equal to zero.");
388388
}
389389
_secondaryAcceptableLatency = value;
390390
}
@@ -449,7 +449,7 @@ public TimeSpan SocketTimeout
449449
{
450450
if (value < TimeSpan.Zero)
451451
{
452-
throw new ArgumentOutOfRangeException("value", "SocketTimeout must be larger than or equal to zero.");
452+
throw new ArgumentOutOfRangeException("value", "SocketTimeout must be greater than or equal to zero.");
453453
}
454454
_socketTimeout = value;
455455
}
@@ -496,7 +496,7 @@ public double WaitQueueMultiple
496496
{
497497
if (value <= 0.0)
498498
{
499-
throw new ArgumentOutOfRangeException("value", "WaitQueueMultiple must be larger than zero.");
499+
throw new ArgumentOutOfRangeException("value", "WaitQueueMultiple must be greater than zero.");
500500
}
501501
_waitQueueMultiple = value;
502502
_waitQueueSize = 0;
@@ -513,7 +513,7 @@ public int WaitQueueSize
513513
{
514514
if (value <= 0)
515515
{
516-
throw new ArgumentOutOfRangeException("value", "WaitQueueSize must be larger than 0.");
516+
throw new ArgumentOutOfRangeException("value", "WaitQueueSize must be greater than zero.");
517517
}
518518
_waitQueueSize = value;
519519
_waitQueueMultiple = 0.0;
@@ -530,7 +530,7 @@ public TimeSpan WaitQueueTimeout
530530
{
531531
if (value < TimeSpan.Zero)
532532
{
533-
throw new ArgumentOutOfRangeException("value", "WaitQueueTimeout must be larger than or equal to zero.");
533+
throw new ArgumentOutOfRangeException("value", "WaitQueueTimeout must be greater than or equal to zero.");
534534
}
535535
_waitQueueTimeout = value;
536536
}
@@ -547,7 +547,7 @@ public TimeSpan? WTimeout
547547
if (value != null) { EnsureFireAndForgetIsNotTrue("WTimeout"); }
548548
if (value != null && value.Value < TimeSpan.Zero)
549549
{
550-
throw new ArgumentOutOfRangeException("value", "WTimeout must be larger than or equal to zero.");
550+
throw new ArgumentOutOfRangeException("value", "WTimeout must be greater than or equal to zero.");
551551
}
552552
_wTimeout = value;
553553
}

Driver/Core/WriteConcern.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,12 @@ private void ThrowFrozenException()
364364
/// </summary>
365365
public abstract class WValue
366366
{
367+
// constructors
368+
// internal constructor prevents users from creating new subclasses of WValue
369+
internal WValue()
370+
{
371+
}
372+
367373
// implicit conversions
368374
/// <summary>
369375
/// Converts an int value to a WValue of type WCount.
@@ -454,7 +460,7 @@ public override int GetHashCode()
454460
/// <summary>
455461
/// Represents an integer "w" value in a WriteConcern.
456462
/// </summary>
457-
public class WCount : WValue
463+
public sealed class WCount : WValue
458464
{
459465
// private fields
460466
private readonly int _value;
@@ -522,7 +528,7 @@ internal override BsonValue ToBsonValue()
522528
/// <summary>
523529
/// Represents a string "w" value in a WriteConcern (the name of a mode).
524530
/// </summary>
525-
public class WMode : WValue
531+
public sealed class WMode : WValue
526532
{
527533
// private fields
528534
private readonly string _value;

0 commit comments

Comments
 (0)