|
1 | | -namespace Dawn |
| 1 | +#nullable enable |
| 2 | + |
| 3 | +namespace Dawn |
2 | 4 | { |
3 | 5 | using System; |
| 6 | + using System.ComponentModel; |
4 | 7 | using System.Diagnostics; |
5 | 8 | using JetBrains.Annotations; |
6 | 9 |
|
@@ -29,7 +32,7 @@ public static partial class Guard |
29 | 32 | [DebuggerStepThrough] |
30 | 33 | [GuardFunction("Double", "gnan")] |
31 | 34 | public static ref readonly ArgumentInfo<double> NaN( |
32 | | - in this ArgumentInfo<double> argument, Func<double, string> message = null) |
| 35 | + in this ArgumentInfo<double> argument, Func<double, string>? message = null) |
33 | 36 | { |
34 | 37 | if (!double.IsNaN(argument.Value)) |
35 | 38 | { |
@@ -70,11 +73,11 @@ public static ref readonly ArgumentInfo<double> NaN( |
70 | 73 | [DebuggerStepThrough] |
71 | 74 | [GuardFunction("Double", "gnan")] |
72 | 75 | public static ref readonly ArgumentInfo<double?> NaN( |
73 | | - in this ArgumentInfo<double?> argument, Func<double?, string> message = null) |
| 76 | + in this ArgumentInfo<double?> argument, Func<double?, string>? message = null) |
74 | 77 | { |
75 | 78 | if (argument.HasValue()) |
76 | 79 | { |
77 | | - var value = argument.Value.Value; |
| 80 | + var value = argument.GetValueOrDefault(); |
78 | 81 | if (!double.IsNaN(value)) |
79 | 82 | { |
80 | 83 | var m = message?.Invoke(value) ?? Messages.NaN(argument); |
@@ -108,7 +111,7 @@ public static ref readonly ArgumentInfo<double> NaN( |
108 | 111 | [DebuggerStepThrough] |
109 | 112 | [GuardFunction("Double", "gnnan")] |
110 | 113 | public static ref readonly ArgumentInfo<double> NotNaN( |
111 | | - in this ArgumentInfo<double> argument, string message = null) |
| 114 | + in this ArgumentInfo<double> argument, string? message = null) |
112 | 115 | { |
113 | 116 | if (double.IsNaN(argument.Value)) |
114 | 117 | { |
@@ -142,11 +145,11 @@ public static ref readonly ArgumentInfo<double> NotNaN( |
142 | 145 | [DebuggerStepThrough] |
143 | 146 | [GuardFunction("Double", "gnnan")] |
144 | 147 | public static ref readonly ArgumentInfo<double?> NotNaN( |
145 | | - in this ArgumentInfo<double?> argument, string message = null) |
| 148 | + in this ArgumentInfo<double?> argument, string? message = null) |
146 | 149 | { |
147 | 150 | if (argument.HasValue()) |
148 | 151 | { |
149 | | - var value = argument.Value.Value; |
| 152 | + var value = argument.GetValueOrDefault(); |
150 | 153 | if (double.IsNaN(value)) |
151 | 154 | { |
152 | 155 | var m = message ?? Messages.NotNaN(argument); |
@@ -182,7 +185,7 @@ public static ref readonly ArgumentInfo<double> NotNaN( |
182 | 185 | [DebuggerStepThrough] |
183 | 186 | [GuardFunction("Double", "ginf")] |
184 | 187 | public static ref readonly ArgumentInfo<double> Infinity( |
185 | | - in this ArgumentInfo<double> argument, Func<double, string> message = null) |
| 188 | + in this ArgumentInfo<double> argument, Func<double, string>? message = null) |
186 | 189 | { |
187 | 190 | if (!double.IsInfinity(argument.Value)) |
188 | 191 | { |
@@ -226,11 +229,11 @@ public static ref readonly ArgumentInfo<double> Infinity( |
226 | 229 | [DebuggerStepThrough] |
227 | 230 | [GuardFunction("Double", "ginf")] |
228 | 231 | public static ref readonly ArgumentInfo<double?> Infinity( |
229 | | - in this ArgumentInfo<double?> argument, Func<double?, string> message = null) |
| 232 | + in this ArgumentInfo<double?> argument, Func<double?, string>? message = null) |
230 | 233 | { |
231 | 234 | if (argument.HasValue()) |
232 | 235 | { |
233 | | - var value = argument.Value.Value; |
| 236 | + var value = argument.GetValueOrDefault(); |
234 | 237 | if (!double.IsInfinity(value)) |
235 | 238 | { |
236 | 239 | var m = message?.Invoke(value) ?? Messages.Infinity(argument); |
@@ -264,6 +267,7 @@ public static ref readonly ArgumentInfo<double> Infinity( |
264 | 267 | [AssertionMethod] |
265 | 268 | [DebuggerStepThrough] |
266 | 269 | [Obsolete("Use the NotInfinity overload that accepts the message as a `Func<double, string>`.")] |
| 270 | + [EditorBrowsable(EditorBrowsableState.Never)] |
267 | 271 | public static ref readonly ArgumentInfo<double> NotInfinity( |
268 | 272 | in this ArgumentInfo<double> argument, string message) |
269 | 273 | { |
@@ -301,7 +305,7 @@ public static ref readonly ArgumentInfo<double> NotInfinity( |
301 | 305 | [DebuggerStepThrough] |
302 | 306 | [GuardFunction("Double", "gninf")] |
303 | 307 | public static ref readonly ArgumentInfo<double> NotInfinity( |
304 | | - in this ArgumentInfo<double> argument, Func<double, string> message = null) |
| 308 | + in this ArgumentInfo<double> argument, Func<double, string>? message = null) |
305 | 309 | { |
306 | 310 | if (double.IsInfinity(argument.Value)) |
307 | 311 | { |
@@ -335,6 +339,7 @@ public static ref readonly ArgumentInfo<double> NotInfinity( |
335 | 339 | [AssertionMethod] |
336 | 340 | [DebuggerStepThrough] |
337 | 341 | [Obsolete("Use the NotInfinity overload that accepts the message as a `Func<double?, string>`.")] |
| 342 | + [EditorBrowsable(EditorBrowsableState.Never)] |
338 | 343 | public static ref readonly ArgumentInfo<double?> NotInfinity( |
339 | 344 | in this ArgumentInfo<double?> argument, string message) |
340 | 345 | { |
@@ -378,11 +383,11 @@ public static ref readonly ArgumentInfo<double> NotInfinity( |
378 | 383 | [DebuggerStepThrough] |
379 | 384 | [GuardFunction("Double", "gninf")] |
380 | 385 | public static ref readonly ArgumentInfo<double?> NotInfinity( |
381 | | - in this ArgumentInfo<double?> argument, Func<double?, string> message = null) |
| 386 | + in this ArgumentInfo<double?> argument, Func<double?, string>? message = null) |
382 | 387 | { |
383 | 388 | if (argument.HasValue()) |
384 | 389 | { |
385 | | - var value = argument.Value.Value; |
| 390 | + var value = argument.GetValueOrDefault(); |
386 | 391 | if (double.IsInfinity(value)) |
387 | 392 | { |
388 | 393 | var m = message?.Invoke(value) ?? Messages.NotInfinity(argument); |
@@ -417,7 +422,7 @@ public static ref readonly ArgumentInfo<double> NotInfinity( |
417 | 422 | [DebuggerStepThrough] |
418 | 423 | [GuardFunction("Double", "gposinf")] |
419 | 424 | public static ref readonly ArgumentInfo<double> PositiveInfinity( |
420 | | - in this ArgumentInfo<double> argument, Func<double, string> message = null) |
| 425 | + in this ArgumentInfo<double> argument, Func<double, string>? message = null) |
421 | 426 | { |
422 | 427 | if (!double.IsPositiveInfinity(argument.Value)) |
423 | 428 | { |
@@ -458,11 +463,11 @@ public static ref readonly ArgumentInfo<double> PositiveInfinity( |
458 | 463 | [DebuggerStepThrough] |
459 | 464 | [GuardFunction("Double", "gposinf")] |
460 | 465 | public static ref readonly ArgumentInfo<double?> PositiveInfinity( |
461 | | - in this ArgumentInfo<double?> argument, Func<double?, string> message = null) |
| 466 | + in this ArgumentInfo<double?> argument, Func<double?, string>? message = null) |
462 | 467 | { |
463 | 468 | if (argument.HasValue()) |
464 | 469 | { |
465 | | - var value = argument.Value.Value; |
| 470 | + var value = argument.GetValueOrDefault(); |
466 | 471 | if (!double.IsPositiveInfinity(value)) |
467 | 472 | { |
468 | 473 | var m = message?.Invoke(value) ?? Messages.PositiveInfinity(argument); |
@@ -496,7 +501,7 @@ public static ref readonly ArgumentInfo<double> PositiveInfinity( |
496 | 501 | [DebuggerStepThrough] |
497 | 502 | [GuardFunction("Double", "gnposinf")] |
498 | 503 | public static ref readonly ArgumentInfo<double> NotPositiveInfinity( |
499 | | - in this ArgumentInfo<double> argument, string message = null) |
| 504 | + in this ArgumentInfo<double> argument, string? message = null) |
500 | 505 | { |
501 | 506 | if (double.IsPositiveInfinity(argument.Value)) |
502 | 507 | { |
@@ -530,11 +535,11 @@ public static ref readonly ArgumentInfo<double> NotPositiveInfinity( |
530 | 535 | [DebuggerStepThrough] |
531 | 536 | [GuardFunction("Double", "gnposinf")] |
532 | 537 | public static ref readonly ArgumentInfo<double?> NotPositiveInfinity( |
533 | | - in this ArgumentInfo<double?> argument, string message = null) |
| 538 | + in this ArgumentInfo<double?> argument, string? message = null) |
534 | 539 | { |
535 | 540 | if (argument.HasValue()) |
536 | 541 | { |
537 | | - var value = argument.Value.Value; |
| 542 | + var value = argument.GetValueOrDefault(); |
538 | 543 | if (double.IsPositiveInfinity(value)) |
539 | 544 | { |
540 | 545 | var m = message ?? Messages.NotPositiveInfinity(argument); |
@@ -569,7 +574,7 @@ public static ref readonly ArgumentInfo<double> NotPositiveInfinity( |
569 | 574 | [DebuggerStepThrough] |
570 | 575 | [GuardFunction("Double", "gneginf")] |
571 | 576 | public static ref readonly ArgumentInfo<double> NegativeInfinity( |
572 | | - in this ArgumentInfo<double> argument, Func<double, string> message = null) |
| 577 | + in this ArgumentInfo<double> argument, Func<double, string>? message = null) |
573 | 578 | { |
574 | 579 | if (!double.IsNegativeInfinity(argument.Value)) |
575 | 580 | { |
@@ -610,11 +615,11 @@ public static ref readonly ArgumentInfo<double> NegativeInfinity( |
610 | 615 | [DebuggerStepThrough] |
611 | 616 | [GuardFunction("Double", "gneginf")] |
612 | 617 | public static ref readonly ArgumentInfo<double?> NegativeInfinity( |
613 | | - in this ArgumentInfo<double?> argument, Func<double?, string> message = null) |
| 618 | + in this ArgumentInfo<double?> argument, Func<double?, string>? message = null) |
614 | 619 | { |
615 | 620 | if (argument.HasValue()) |
616 | 621 | { |
617 | | - var value = argument.Value.Value; |
| 622 | + var value = argument.GetValueOrDefault(); |
618 | 623 | if (!double.IsNegativeInfinity(value)) |
619 | 624 | { |
620 | 625 | var m = message?.Invoke(value) ?? Messages.NegativeInfinity(argument); |
@@ -648,7 +653,7 @@ public static ref readonly ArgumentInfo<double> NegativeInfinity( |
648 | 653 | [DebuggerStepThrough] |
649 | 654 | [GuardFunction("Double", "gnneginf")] |
650 | 655 | public static ref readonly ArgumentInfo<double> NotNegativeInfinity( |
651 | | - in this ArgumentInfo<double> argument, string message = null) |
| 656 | + in this ArgumentInfo<double> argument, string? message = null) |
652 | 657 | { |
653 | 658 | if (double.IsNegativeInfinity(argument.Value)) |
654 | 659 | { |
@@ -682,11 +687,11 @@ public static ref readonly ArgumentInfo<double> NotNegativeInfinity( |
682 | 687 | [DebuggerStepThrough] |
683 | 688 | [GuardFunction("Double", "gnneginf")] |
684 | 689 | public static ref readonly ArgumentInfo<double?> NotNegativeInfinity( |
685 | | - in this ArgumentInfo<double?> argument, string message = null) |
| 690 | + in this ArgumentInfo<double?> argument, string? message = null) |
686 | 691 | { |
687 | 692 | if (argument.HasValue()) |
688 | 693 | { |
689 | | - var value = argument.Value.Value; |
| 694 | + var value = argument.GetValueOrDefault(); |
690 | 695 | if (double.IsNegativeInfinity(value)) |
691 | 696 | { |
692 | 697 | var m = message ?? Messages.NotNegativeInfinity(argument); |
@@ -722,7 +727,7 @@ public static ref readonly ArgumentInfo<double> Equal( |
722 | 727 | in this ArgumentInfo<double> argument, |
723 | 728 | double other, |
724 | 729 | double delta, |
725 | | - Func<double, double, string> message = null) |
| 730 | + Func<double, double, string>? message = null) |
726 | 731 | { |
727 | 732 | var diff = Math.Abs(argument.Value - other); |
728 | 733 | if (diff > delta) |
@@ -759,11 +764,11 @@ public static ref readonly ArgumentInfo<double> Equal( |
759 | 764 | in this ArgumentInfo<double?> argument, |
760 | 765 | double other, |
761 | 766 | double delta, |
762 | | - Func<double, double, string> message = null) |
| 767 | + Func<double, double, string>? message = null) |
763 | 768 | { |
764 | 769 | if (argument.HasValue()) |
765 | 770 | { |
766 | | - var value = argument.Value.Value; |
| 771 | + var value = argument.GetValueOrDefault(); |
767 | 772 | var diff = Math.Abs(value - other); |
768 | 773 | if (diff > delta) |
769 | 774 | { |
@@ -800,7 +805,7 @@ public static ref readonly ArgumentInfo<double> NotEqual( |
800 | 805 | in this ArgumentInfo<double> argument, |
801 | 806 | double other, |
802 | 807 | double delta, |
803 | | - Func<double, double, string> message = null) |
| 808 | + Func<double, double, string>? message = null) |
804 | 809 | { |
805 | 810 | var diff = Math.Abs(argument.Value - other); |
806 | 811 | if (diff <= delta) |
@@ -837,11 +842,11 @@ public static ref readonly ArgumentInfo<double> NotEqual( |
837 | 842 | in this ArgumentInfo<double?> argument, |
838 | 843 | double other, |
839 | 844 | double delta, |
840 | | - Func<double, double, string> message = null) |
| 845 | + Func<double, double, string>? message = null) |
841 | 846 | { |
842 | 847 | if (argument.HasValue()) |
843 | 848 | { |
844 | | - var value = argument.Value.Value; |
| 849 | + var value = argument.GetValueOrDefault(); |
845 | 850 | var diff = Math.Abs(value - other); |
846 | 851 | if (diff <= delta) |
847 | 852 | { |
|
0 commit comments