File tree Expand file tree Collapse file tree 3 files changed +42
-7
lines changed
Expand file tree Collapse file tree 3 files changed +42
-7
lines changed Original file line number Diff line number Diff line change @@ -359,4 +359,27 @@ public static async Task FlattenTask()
359359 await ThrowsAsync < InvalidOperationException > ( static ( ) => Task . FromResult ( Optional . None < int > ( ) ) . Flatten ( ) ) ;
360360 Equal ( 42 , await Task . FromResult ( Optional . Some ( 42 ) ) . Flatten ( ) ) ;
361361 }
362+
363+ [ Fact ]
364+ public static void MiscOperators ( )
365+ {
366+ Optional < int > result = 20 ;
367+ False ( ! result ) ;
368+
369+ if ( result )
370+ {
371+ }
372+ else
373+ {
374+ Fail ( "Optional has no value" ) ;
375+ }
376+
377+ result = Optional < int > . None ;
378+ True ( ! result ) ;
379+
380+ if ( result )
381+ {
382+ Fail ( "Optional has value" ) ;
383+ }
384+ }
362385}
Original file line number Diff line number Diff line change @@ -84,8 +84,14 @@ public static virtual bool operator true(in TSelf container)
8484 /// </summary>
8585 /// <param name="container">The container to check.</param>
8686 /// <returns><see langword="true"/> if this container has no value; otherwise, <see langword="false"/>.</returns>
87- public static virtual bool operator false( in TSelf container )
88- => container . HasValue is false ;
87+ public static virtual bool operator false( in TSelf container ) => ! container ;
88+
89+ /// <summary>
90+ /// Checks whether the container has no value.
91+ /// </summary>
92+ /// <param name="container">The container to check.</param>
93+ /// <returns><see langword="true"/> if this container has no value; otherwise, <see langword="false"/>.</returns>
94+ public static virtual bool operator ! ( in TSelf container ) => container . HasValue is false ;
8995
9096 /// <summary>
9197 /// Returns the value if present; otherwise return default value.
Original file line number Diff line number Diff line change @@ -772,16 +772,22 @@ public bool Equals(object? other, IEqualityComparer comparer)
772772 /// </summary>
773773 /// <param name="optional">The container to check.</param>
774774 /// <returns><see langword="true"/> if this container has value; otherwise, <see langword="false"/>.</returns>
775- /// <see cref="HasValue"/>
776- [ MemberNotNullWhen ( true , nameof ( ValueOrDefault ) ) ]
775+ /// <seealso cref="HasValue"/>
777776 public static bool operator true( in Optional < T > optional ) => optional . HasValue ;
778777
779778 /// <summary>
780779 /// Checks whether the container has no value.
781780 /// </summary>
782781 /// <param name="optional">The container to check.</param>
783782 /// <returns><see langword="true"/> if this container has no value; otherwise, <see langword="false"/>.</returns>
784- /// <see cref="HasValue"/>
785- [ MemberNotNullWhen ( false , nameof ( ValueOrDefault ) ) ]
786- public static bool operator false( in Optional < T > optional ) => optional . kind < NotEmptyValue ;
783+ /// <seealso cref="HasValue"/>
784+ public static bool operator false( in Optional < T > optional ) => ! optional ;
785+
786+ /// <summary>
787+ /// Checks whether the container has no value.
788+ /// </summary>
789+ /// <param name="optional">The container to check.</param>
790+ /// <returns><see langword="true"/> if this container has no value; otherwise, <see langword="false"/>.</returns>
791+ /// <seealso cref="HasValue"/>
792+ public static bool operator ! ( in Optional < T > optional ) => optional . kind < NotEmptyValue ;
787793}
You can’t perform that action at this time.
0 commit comments