11namespace Matchmaker . Linq ;
22
33using System ;
4+ #if NETSTANDARD2_1_OR_GREATER || NET8_0_OR_GREATER
45using System . Diagnostics . CodeAnalysis ;
6+ #endif
57using System . Threading . Tasks ;
68
79/// <summary>
@@ -19,7 +21,9 @@ public static class MatchResultExtensions
1921 /// <returns>
2022 /// The result's value if it's successful, or the default one otherwise.
2123 /// </returns>
24+ #if NETSTANDARD2_1_OR_GREATER || NET8_0_OR_GREATER
2225 [ return : MaybeNull ]
26+ #endif
2327 public static T GetValueOrDefault < T > ( this MatchResult < T > result ) =>
2428 result ! . GetValueOrDefault ( default ( T ) ) ;
2529
@@ -32,8 +36,15 @@ public static T GetValueOrDefault<T>(this MatchResult<T> result) =>
3236 /// <returns>
3337 /// The result's value if it's successful, or the default one otherwise.
3438 /// </returns>
39+ #if NETSTANDARD2_1_OR_GREATER || NET8_0_OR_GREATER
3540 [ return : MaybeNull ]
36- public static T GetValueOrDefault < T > ( this MatchResult < T > result , [ AllowNull ] T defaultValue ) =>
41+ #endif
42+ public static T GetValueOrDefault < T > (
43+ this MatchResult < T > result ,
44+ #if NETSTANDARD2_1_OR_GREATER || NET8_0_OR_GREATER
45+ [ AllowNull ]
46+ #endif
47+ T defaultValue ) =>
3748 result . IsSuccessful ? result . Value : defaultValue ;
3849
3950 /// <summary>
@@ -50,7 +61,9 @@ public static T GetValueOrDefault<T>(this MatchResult<T> result, [AllowNull] T d
5061 /// <exception cref="ArgumentNullException">
5162 /// <paramref name="defaultValueProvider" /> is <see langword="null" />.
5263 /// </exception>
64+ #if NETSTANDARD2_1_OR_GREATER || NET8_0_OR_GREATER
5365 [ return : MaybeNull ]
66+ #endif
5467 public static T GetValueOrDefault < T > ( this MatchResult < T > result , Func < T > defaultValueProvider ) =>
5568 defaultValueProvider != null
5669 ? result . IsSuccessful ? result . Value : defaultValueProvider ( )
@@ -68,7 +81,9 @@ public static T GetValueOrDefault<T>(this MatchResult<T> result, Func<T> default
6881 /// <exception cref="ArgumentNullException">
6982 /// <paramref name="exceptionProvider" /> is <see langword="null" />.
7083 /// </exception>
84+ #if NETSTANDARD2_1_OR_GREATER || NET8_0_OR_GREATER
7185 [ return : MaybeNull ]
86+ #endif
7287 public static T GetValueOrThrow < T > ( this MatchResult < T > result , Func < Exception > exceptionProvider ) =>
7388 exceptionProvider != null
7489 ? result . IsSuccessful ? result . Value : throw exceptionProvider ( )
@@ -225,7 +240,12 @@ public static async Task<T> GetValueOrDefault<T>(this Task<MatchResult<T>> futur
225240 /// <exception cref="ArgumentNullException">
226241 /// <paramref name="futureResult" /> is <see langword="null" />.
227242 /// </exception>
228- public static async Task < T > GetValueOrDefault < T > ( this Task < MatchResult < T > > futureResult , [ AllowNull ] T defaultValue )
243+ public static async Task < T > GetValueOrDefault < T > (
244+ this Task < MatchResult < T > > futureResult ,
245+ #if NETSTANDARD2_1_OR_GREATER || NET8_0_OR_GREATER
246+ [ AllowNull ]
247+ #endif
248+ T defaultValue )
229249 {
230250 var result = await ( futureResult ?? throw new ArgumentNullException ( nameof ( futureResult ) ) ) ;
231251 return result . IsSuccessful ? result . Value ! : defaultValue ! ;
0 commit comments