@@ -199,7 +199,14 @@ public bool Enabled
199
199
set
200
200
{
201
201
if ( _isFrozen ) { ThrowFrozenException ( ) ; }
202
- _enabled = value ;
202
+ if ( value )
203
+ {
204
+ _enabled = true ;
205
+ }
206
+ else
207
+ {
208
+ ResetValues ( ) ;
209
+ }
203
210
}
204
211
}
205
212
@@ -276,25 +283,25 @@ public TimeSpan WTimeout
276
283
277
284
// public operators
278
285
/// <summary>
279
- /// Compares two SafeMode values.
286
+ /// Determines whether two specified SafeMode objects have different values.
280
287
/// </summary>
281
- /// <param name="lhs">The first SafeMode value.</param>
282
- /// <param name="rhs">The other SafeMode value.</param>
283
- /// <returns>True if the values are equal (or both null) .</returns>
284
- public static bool operator = =( SafeMode lhs , SafeMode rhs )
288
+ /// <param name="lhs">The first value to compare, or null .</param>
289
+ /// <param name="rhs">The second value to compare, or null .</param>
290
+ /// <returns>True if the value of lhs is different from the value of rhs; otherwise, false .</returns>
291
+ public static bool operator ! =( SafeMode lhs , SafeMode rhs )
285
292
{
286
- return object . Equals ( lhs , rhs ) ;
293
+ return ! SafeMode . Equals ( lhs , rhs ) ;
287
294
}
288
295
289
296
/// <summary>
290
- /// Compares two SafeMode values .
297
+ /// Determines whether two specified SafeMode objects have the same value .
291
298
/// </summary>
292
- /// <param name="lhs">The first SafeMode value.</param>
293
- /// <param name="rhs">The other SafeMode value.</param>
294
- /// <returns>True if the values are not equal (or one is null and the other is not) .</returns>
295
- public static bool operator ! =( SafeMode lhs , SafeMode rhs )
299
+ /// <param name="lhs">The first value to compare, or null .</param>
300
+ /// <param name="rhs">The second value to compare, or null .</param>
301
+ /// <returns>True if the value of lhs is the same as the value of rhs; otherwise, false .</returns>
302
+ public static bool operator = =( SafeMode lhs , SafeMode rhs )
296
303
{
297
- return ! ( lhs == rhs ) ;
304
+ return SafeMode . Equals ( lhs , rhs ) ;
298
305
}
299
306
300
307
// public static methods
@@ -382,6 +389,18 @@ public static SafeMode Create(int w, TimeSpan wtimeout)
382
389
return Create ( true , false , w , wtimeout ) ;
383
390
}
384
391
392
+ /// <summary>
393
+ /// Determines whether two specified SafeMode objects have the same value.
394
+ /// </summary>
395
+ /// <param name="lhs">The first value to compare, or null.</param>
396
+ /// <param name="rhs">The second value to compare, or null.</param>
397
+ /// <returns>True if the value of lhs is the same as the value of rhs; otherwise, false.</returns>
398
+ public static bool Equals ( SafeMode lhs , SafeMode rhs )
399
+ {
400
+ if ( ( object ) lhs == null ) { return ( object ) rhs == null ; }
401
+ return lhs . Equals ( rhs ) ;
402
+ }
403
+
385
404
// public methods
386
405
/// <summary>
387
406
/// Creates a clone of the SafeMode.
@@ -393,23 +412,24 @@ public SafeMode Clone()
393
412
}
394
413
395
414
/// <summary>
396
- /// Compares two SafeMode values .
415
+ /// Determines whether this instance and a specified object, which must also be a SafeMode object, have the same value .
397
416
/// </summary>
398
- /// <param name="obj">The other SafeMode value .</param>
399
- /// <returns>True if the values are equal .</returns>
417
+ /// <param name="obj">The SafeMode object to compare to this instance .</param>
418
+ /// <returns>True if obj is a SafeMode object and its value is the same as this instance; otherwise, false .</returns>
400
419
public override bool Equals ( object obj )
401
420
{
402
421
return Equals ( obj as SafeMode ) ; // works even if obj is null or of a different type
403
422
}
404
423
405
424
/// <summary>
406
- /// Compares two SafeMode values .
425
+ /// Determines whether this instance and another specified SafeMode object have the same value .
407
426
/// </summary>
408
- /// <param name="rhs">The other SafeMode value .</param>
409
- /// <returns>True if the values are equal .</returns>
427
+ /// <param name="rhs">The SafeMode object to compare to this instance .</param>
428
+ /// <returns>True if the value of the rhs parameter is the same as this instance; otherwise, false .</returns>
410
429
public bool Equals ( SafeMode rhs )
411
430
{
412
- if ( object . ReferenceEquals ( rhs , null ) || GetType ( ) != rhs . GetType ( ) ) { return false ; }
431
+ if ( ( object ) rhs == null || GetType ( ) != rhs . GetType ( ) ) { return false ; }
432
+ if ( ( object ) this == ( object ) rhs ) { return true ; }
413
433
return
414
434
_enabled == rhs . _enabled &&
415
435
_fsync == rhs . _fsync &&
@@ -477,41 +497,45 @@ public override int GetHashCode()
477
497
/// <returns>A string representation of the SafeMode.</returns>
478
498
public override string ToString ( )
479
499
{
480
- if ( _enabled )
500
+ var sb = new StringBuilder ( ) ;
501
+ sb . AppendFormat ( "safe={0}" , _enabled ? "true" : "false" ) ;
502
+ if ( _fsync )
481
503
{
482
- var sb = new StringBuilder ( "safe=true" ) ;
483
- if ( _fsync )
484
- {
485
- sb . Append ( ",fsync=true" ) ;
486
- }
487
- if ( _j )
504
+ sb . Append ( ",fsync=true" ) ;
505
+ }
506
+ if ( _j )
507
+ {
508
+ sb . Append ( ",j=true" ) ;
509
+ }
510
+ if ( _w != 0 || _wmode != null )
511
+ {
512
+ if ( _w != 0 )
488
513
{
489
- sb . Append ( ",j=true" ) ;
514
+ sb . AppendFormat ( ",w={0}" , _w ) ;
490
515
}
491
- if ( _w != 0 || _wmode != null )
516
+ if ( _wmode != null )
492
517
{
493
- if ( _w != 0 )
494
- {
495
- sb . AppendFormat ( ",w={0}" , _w ) ;
496
- }
497
- if ( _wmode != null )
498
- {
499
- sb . AppendFormat ( ",wmode=\" {0}\" " , _wmode ) ;
500
- }
501
- if ( _wtimeout != TimeSpan . Zero )
502
- {
503
- sb . AppendFormat ( ",wtimeout={0}" , _wtimeout ) ;
504
- }
518
+ sb . AppendFormat ( ",wmode=\" {0}\" " , _wmode ) ;
505
519
}
506
- return sb . ToString ( ) ;
507
520
}
508
- else
521
+ if ( _wtimeout != TimeSpan . Zero )
509
522
{
510
- return "safe=false" ;
523
+ sb . AppendFormat ( ",wtimeout={0}" , _wtimeout ) ;
511
524
}
525
+ return sb . ToString ( ) ;
512
526
}
513
527
514
528
// private methods
529
+ private void ResetValues ( )
530
+ {
531
+ _enabled = false ;
532
+ _fsync = false ;
533
+ _j = false ;
534
+ _w = 0 ;
535
+ _wmode = null ;
536
+ _wtimeout = TimeSpan . Zero ;
537
+ }
538
+
515
539
private void ThrowFrozenException ( )
516
540
{
517
541
throw new InvalidOperationException ( "SafeMode has been frozen and no further changes are allowed." ) ;
0 commit comments