@@ -195,13 +195,16 @@ public bool? FireAndForget
195195 get { return _fireAndForget ; }
196196 set
197197 {
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 )
203199 {
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+ }
205208 }
206209 _fireAndForget = value ;
207210 base [ "fireAndForget" ] = ( value == null ) ? null : XmlConvert . ToString ( value . Value ) ;
@@ -230,7 +233,8 @@ public GuidRepresentation GuidRepresentation
230233 get { return _guidRepresentation ; }
231234 set
232235 {
233- base [ "uuidRepresentation" ] = _guidRepresentation = value ;
236+ _guidRepresentation = value ;
237+ base [ "uuidRepresentation" ] = ( value == GuidRepresentation . CSharpLegacy ) ? "csharpLegacy" : MongoUtils . ToCamelCase ( value . ToString ( ) ) ;
234238 }
235239 }
236240
@@ -363,28 +367,28 @@ public ReadPreference ReadPreference
363367 }
364368 set
365369 {
366- if ( _slaveOk . HasValue )
370+ if ( value != null && _slaveOk . HasValue )
367371 {
368372 throw new InvalidOperationException ( "ReadPreference cannot be set because SlaveOk already has a value." ) ;
369373 }
370374 _readPreference = value ;
371375
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 )
378378 {
379379 var readPreferenceTagsString = string . Join (
380380 "|" ,
381- _readPreference . TagSets . Select ( ts => string . Join (
381+ value . TagSets . Select ( ts => string . Join (
382382 "," ,
383383 ts . Tags . Select ( t => string . Format ( "{0}:{1}" , t . Name , t . Value ) ) . ToArray ( )
384384 ) ) . ToArray ( )
385385 ) ;
386386 base [ "readPreferenceTags" ] = readPreferenceTagsString ;
387387 }
388+ else
389+ {
390+ base [ "readPreferenceTags" ] = null ;
391+ }
388392 }
389393 }
390394
@@ -409,13 +413,16 @@ public bool? Safe
409413 get { return _safe ; }
410414 set
411415 {
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 )
417417 {
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+ }
419426 }
420427 _safe = value ;
421428 base [ "safe" ] = ( value == null ) ? null : XmlConvert . ToString ( value . Value ) ;
@@ -489,7 +496,7 @@ public TimeSpan SecondaryAcceptableLatency
489496 public MongoServerAddress Server
490497 {
491498 get { return ( _servers == null ) ? null : _servers . Single ( ) ; }
492- set { Servers = new [ ] { value } ; }
499+ set { Servers = ( value == null ) ? null : new [ ] { value } ; }
493500 }
494501
495502 /// <summary>
@@ -501,7 +508,7 @@ public IEnumerable<MongoServerAddress> Servers
501508 set
502509 {
503510 _servers = value ;
504- base [ "server" ] = GetServersString ( ) ;
511+ base [ "server" ] = ( value == null ) ? null : GetServersString ( value ) ;
505512 }
506513 }
507514
@@ -912,10 +919,10 @@ private void EnsureFireAndForgetIsNotTrue(string propertyName)
912919 }
913920 }
914921
915- private string GetServersString ( )
922+ private string GetServersString ( IEnumerable < MongoServerAddress > servers )
916923 {
917924 var sb = new StringBuilder ( ) ;
918- foreach ( var server in _servers )
925+ foreach ( var server in servers )
919926 {
920927 if ( sb . Length > 0 ) { sb . Append ( "," ) ; }
921928 if ( server . Port == 27017 )
0 commit comments