@@ -195,13 +195,16 @@ public bool? FireAndForget
195
195
get { return _fireAndForget ; }
196
196
set
197
197
{
198
- if ( _safe != null )
199
- {
200
- throw new InvalidOperationException ( "FireAndForget and Safe are mutually exclusive." ) ;
201
- }
202
- if ( ( value != null && value . Value ) && AnyWriteConcernSettingsAreSet ( ) )
198
+ if ( value != null )
203
199
{
204
- throw new InvalidOperationException ( "FireAndForget cannot be set to true if any other write concern values have been set." ) ;
200
+ if ( _safe != null )
201
+ {
202
+ throw new InvalidOperationException ( "FireAndForget and Safe are mutually exclusive." ) ;
203
+ }
204
+ if ( value . Value && AnyWriteConcernSettingsAreSet ( ) )
205
+ {
206
+ throw new InvalidOperationException ( "FireAndForget cannot be set to true if any other write concern values have been set." ) ;
207
+ }
205
208
}
206
209
_fireAndForget = value ;
207
210
base [ "fireAndForget" ] = ( value == null ) ? null : XmlConvert . ToString ( value . Value ) ;
@@ -230,7 +233,8 @@ public GuidRepresentation GuidRepresentation
230
233
get { return _guidRepresentation ; }
231
234
set
232
235
{
233
- base [ "uuidRepresentation" ] = _guidRepresentation = value ;
236
+ _guidRepresentation = value ;
237
+ base [ "uuidRepresentation" ] = ( value == GuidRepresentation . CSharpLegacy ) ? "csharpLegacy" : MongoUtils . ToCamelCase ( value . ToString ( ) ) ;
234
238
}
235
239
}
236
240
@@ -363,28 +367,28 @@ public ReadPreference ReadPreference
363
367
}
364
368
set
365
369
{
366
- if ( _slaveOk . HasValue )
370
+ if ( value != null && _slaveOk . HasValue )
367
371
{
368
372
throw new InvalidOperationException ( "ReadPreference cannot be set because SlaveOk already has a value." ) ;
369
373
}
370
374
_readPreference = value ;
371
375
372
- base [ "readPreference" ] = MongoUtils . ToCamelCase ( _readPreference . ReadPreferenceMode . ToString ( ) ) ;
373
- if ( _readPreference . TagSets == null )
374
- {
375
- base [ "readPreferenceTags" ] = null ;
376
- }
377
- else
376
+ base [ "readPreference" ] = ( value == null ) ? null : MongoUtils . ToCamelCase ( value . ReadPreferenceMode . ToString ( ) ) ;
377
+ if ( value != null && value . TagSets != null )
378
378
{
379
379
var readPreferenceTagsString = string . Join (
380
380
"|" ,
381
- _readPreference . TagSets . Select ( ts => string . Join (
381
+ value . TagSets . Select ( ts => string . Join (
382
382
"," ,
383
383
ts . Tags . Select ( t => string . Format ( "{0}:{1}" , t . Name , t . Value ) ) . ToArray ( )
384
384
) ) . ToArray ( )
385
385
) ;
386
386
base [ "readPreferenceTags" ] = readPreferenceTagsString ;
387
387
}
388
+ else
389
+ {
390
+ base [ "readPreferenceTags" ] = null ;
391
+ }
388
392
}
389
393
}
390
394
@@ -409,13 +413,16 @@ public bool? Safe
409
413
get { return _safe ; }
410
414
set
411
415
{
412
- if ( _fireAndForget != null )
413
- {
414
- throw new InvalidOperationException ( "FireAndForget and Safe are mutually exclusive." ) ;
415
- }
416
- if ( ( value != null && ! value . Value ) && AnyWriteConcernSettingsAreSet ( ) )
416
+ if ( value != null )
417
417
{
418
- throw new InvalidOperationException ( "Safe cannot be set to false if any other write concern values have been set." ) ;
418
+ if ( _fireAndForget != null )
419
+ {
420
+ throw new InvalidOperationException ( "FireAndForget and Safe are mutually exclusive." ) ;
421
+ }
422
+ if ( ! value . Value && AnyWriteConcernSettingsAreSet ( ) )
423
+ {
424
+ throw new InvalidOperationException ( "Safe cannot be set to false if any other write concern values have been set." ) ;
425
+ }
419
426
}
420
427
_safe = value ;
421
428
base [ "safe" ] = ( value == null ) ? null : XmlConvert . ToString ( value . Value ) ;
@@ -489,7 +496,7 @@ public TimeSpan SecondaryAcceptableLatency
489
496
public MongoServerAddress Server
490
497
{
491
498
get { return ( _servers == null ) ? null : _servers . Single ( ) ; }
492
- set { Servers = new [ ] { value } ; }
499
+ set { Servers = ( value == null ) ? null : new [ ] { value } ; }
493
500
}
494
501
495
502
/// <summary>
@@ -501,7 +508,7 @@ public IEnumerable<MongoServerAddress> Servers
501
508
set
502
509
{
503
510
_servers = value ;
504
- base [ "server" ] = GetServersString ( ) ;
511
+ base [ "server" ] = ( value == null ) ? null : GetServersString ( value ) ;
505
512
}
506
513
}
507
514
@@ -912,10 +919,10 @@ private void EnsureFireAndForgetIsNotTrue(string propertyName)
912
919
}
913
920
}
914
921
915
- private string GetServersString ( )
922
+ private string GetServersString ( IEnumerable < MongoServerAddress > servers )
916
923
{
917
924
var sb = new StringBuilder ( ) ;
918
- foreach ( var server in _servers )
925
+ foreach ( var server in servers )
919
926
{
920
927
if ( sb . Length > 0 ) { sb . Append ( "," ) ; }
921
928
if ( server . Port == 27017 )
0 commit comments