File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
CSharpFunctionalExtensions.Tests/MaybeTests
CSharpFunctionalExtensions/Maybe Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,15 @@ public void Maybe_From_without_type_parameter_creates_new_maybe()
126126 withoutTypeParam . Should ( ) . NotBe ( differentValueTypeParam ) ;
127127 }
128128
129+ [ Fact ]
130+ public void Can_cast_non_generic_maybe_none_to_maybe_none ( )
131+ {
132+ Maybe < int > maybe = Maybe . None ;
133+
134+ maybe . HasValue . Should ( ) . BeFalse ( ) ;
135+ maybe . HasNoValue . Should ( ) . BeTrue ( ) ;
136+ }
137+
129138 private class MyClass
130139 {
131140 public override string ToString ( )
Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ public static implicit operator Maybe<T>(T value)
4747 return new Maybe < T > ( value ) ;
4848 }
4949
50+ public static implicit operator Maybe < T > ( Maybe value ) => None ;
51+
5052 public static Maybe < T > From ( T obj )
5153 {
5254 return new Maybe < T > ( obj ) ;
@@ -127,10 +129,12 @@ public override string ToString()
127129 }
128130
129131 /// <summary>
130- /// Non-generic entrypoint for <see cref="Maybe{T}" /> methods
132+ /// Non-generic entrypoint for <see cref="Maybe{T}" /> members
131133 /// </summary>
132- public static class Maybe
134+ public struct Maybe
133135 {
136+ public static Maybe None => new Maybe ( ) ;
137+
134138 /// <summary>
135139 /// Creates a new <see cref="Maybe{T}" /> from the provided <paramref name="value"/>
136140 /// </summary>
You can’t perform that action at this time.
0 commit comments