1
1
namespace Danom ;
2
2
3
3
/// <summary>
4
- /// Contains extension methods for <see cref="IOption {T}"/> that allow for
4
+ /// Contains extension methods for <see cref="Option {T}"/> that allow for
5
5
/// converting between nullable types and options.
6
6
/// </summary>
7
7
public static class OptionNullableExtensions
@@ -12,7 +12,7 @@ public static class OptionNullableExtensions
12
12
/// <typeparam name="T"></typeparam>
13
13
/// <param name="x"></param>
14
14
/// <returns></returns>
15
- public static IOption < T > ToOption < T > ( this T ? x ) =>
15
+ public static Option < T > ToOption < T > ( this T ? x ) =>
16
16
x is not null && ( ! Equals ( x , default ( T ) ) ) ? Option < T > . Some ( x ) : Option < T > . None ( ) ;
17
17
18
18
/// <summary>
@@ -21,15 +21,15 @@ public static IOption<T> ToOption<T>(this T? x) =>
21
21
/// <typeparam name="T"></typeparam>
22
22
/// <param name="x"></param>
23
23
/// <returns></returns>
24
- public static IOption < T > ToOption < T > ( this T ? x ) where T : struct =>
24
+ public static Option < T > ToOption < T > ( this T ? x ) where T : struct =>
25
25
( x is T t ) ? Option < T > . Some ( t ) : Option < T > . None ( ) ;
26
26
27
27
/// <summary>
28
28
/// Converts a nullable string to an option.
29
29
/// </summary>
30
30
/// <param name="x"></param>
31
31
/// <returns></returns>
32
- public static IOption < string > ToOption ( this string ? x ) =>
32
+ public static Option < string > ToOption ( this string ? x ) =>
33
33
x is not null && ! string . IsNullOrWhiteSpace ( x ) ? Option < string > . Some ( x ) : Option < string > . None ( ) ;
34
34
35
35
/// <summary>
@@ -38,102 +38,102 @@ public static IOption<string> ToOption(this string? x) =>
38
38
/// <typeparam name="T"></typeparam>
39
39
/// <param name="option"></param>
40
40
/// <returns></returns>
41
- public static T ? ToNullable < T > ( this IOption < T > option ) =>
41
+ public static T ? ToNullable < T > ( this Option < T > option ) =>
42
42
option . Match ( some : x => x , none : ( ) => default ! ) ;
43
43
44
44
/// <summary>
45
45
/// Converts a char option to a nullable value.
46
46
/// </summary>
47
47
/// <param name="option"></param>
48
48
/// <returns></returns>
49
- public static char ? ToNullable ( this IOption < char > option ) =>
49
+ public static char ? ToNullable ( this Option < char > option ) =>
50
50
option . Match ( x => new char ? ( x ) , ( ) => null ) ;
51
51
52
52
/// <summary>
53
53
/// Converts a bool option to a nullable value.
54
54
/// </summary>
55
55
/// <param name="option"></param>
56
56
/// <returns></returns>
57
- public static bool ? ToNullable ( this IOption < bool > option ) =>
57
+ public static bool ? ToNullable ( this Option < bool > option ) =>
58
58
option . Match ( x => new bool ? ( x ) , ( ) => null ) ;
59
59
60
60
/// <summary>
61
61
/// Converts a byte option to a nullable value.
62
62
/// </summary>
63
63
/// <param name="option"></param>
64
64
/// <returns></returns>
65
- public static byte ? ToNullable ( this IOption < byte > option ) =>
65
+ public static byte ? ToNullable ( this Option < byte > option ) =>
66
66
option . Match ( x => new byte ? ( x ) , ( ) => null ) ;
67
67
68
68
/// <summary>
69
69
/// Converts a short option to a nullable value.
70
70
/// </summary>
71
71
/// <param name="option"></param>
72
72
/// <returns></returns>
73
- public static short ? ToNullable ( this IOption < short > option ) =>
73
+ public static short ? ToNullable ( this Option < short > option ) =>
74
74
option . Match ( x => new short ? ( x ) , ( ) => null ) ;
75
75
76
76
/// <summary>
77
77
/// Converts a ushort option to a nullable value.
78
78
/// </summary>
79
79
/// <param name="option"></param>
80
80
/// <returns></returns>
81
- public static int ? ToNullable ( this IOption < int > option ) =>
81
+ public static int ? ToNullable ( this Option < int > option ) =>
82
82
option . Match ( x => new int ? ( x ) , ( ) => null ) ;
83
83
84
84
/// <summary>
85
85
/// Converts a uint option to a nullable value.
86
86
/// </summary>
87
87
/// <param name="option"></param>
88
88
/// <returns></returns>/
89
- public static long ? ToNullable ( this IOption < long > option ) =>
89
+ public static long ? ToNullable ( this Option < long > option ) =>
90
90
option . Match ( x => new long ? ( x ) , ( ) => null ) ;
91
91
92
92
/// <summary>
93
93
/// Converts a ulong option to a nullable value.
94
94
/// </summary>
95
95
/// <param name="option"></param>
96
96
/// <returns></returns>
97
- public static decimal ? ToNullable ( this IOption < decimal > option ) =>
97
+ public static decimal ? ToNullable ( this Option < decimal > option ) =>
98
98
option . Match ( x => new decimal ? ( x ) , ( ) => null ) ;
99
99
100
100
/// <summary>
101
101
/// Converts a double option to a nullable value.
102
102
/// </summary>
103
103
/// <param name="option"></param>
104
104
/// <returns></returns>
105
- public static double ? ToNullable ( this IOption < double > option ) =>
105
+ public static double ? ToNullable ( this Option < double > option ) =>
106
106
option . Match ( x => new double ? ( x ) , ( ) => null ) ;
107
107
108
108
/// <summary>
109
109
/// Converts a float option to a nullable value.
110
110
/// </summary>
111
111
/// <param name="option"></param>
112
112
/// <returns></returns>
113
- public static float ? ToNullable ( this IOption < float > option ) =>
113
+ public static float ? ToNullable ( this Option < float > option ) =>
114
114
option . Match ( x => new float ? ( x ) , ( ) => null ) ;
115
115
116
116
/// <summary>
117
117
/// Converts a decimal option to a nullable value.
118
118
/// </summary>
119
119
/// <param name="option"></param>
120
120
/// <returns></returns>
121
- public static Guid ? ToNullable ( this IOption < Guid > option ) =>
121
+ public static Guid ? ToNullable ( this Option < Guid > option ) =>
122
122
option . Match ( x => new Guid ? ( x ) , ( ) => null ) ;
123
123
124
124
/// <summary>
125
125
/// Converts a DateTime option to a nullable value.
126
126
/// </summary>
127
127
/// <param name="option"></param>
128
128
/// <returns></returns>
129
- public static DateTime ? ToNullable ( this IOption < DateTime > option ) =>
129
+ public static DateTime ? ToNullable ( this Option < DateTime > option ) =>
130
130
option . Match ( x => new DateTime ? ( x ) , ( ) => null ) ;
131
131
132
132
/// <summary>
133
133
/// Converts a DateTimeOffset option to a nullable value.
134
134
/// </summary>
135
135
/// <param name="option"></param>
136
136
/// <returns></returns>
137
- public static DateOnly ? ToNullable ( this IOption < DateOnly > option ) =>
137
+ public static DateOnly ? ToNullable ( this Option < DateOnly > option ) =>
138
138
option . Match ( x => new DateOnly ? ( x ) , ( ) => null ) ;
139
139
}
0 commit comments