1- using System ;
1+ using System ;
2+ #if NETCOREAPP3_0_OR_GREATER
23using System . Runtime . CompilerServices ;
4+ #endif
35
46namespace SpanExtensions
57{
68 static class InternalExtensions
79 {
10+ #if NETCOREAPP3_0_OR_GREATER
811 /// <summary>
912 /// Throws an <see cref="ArgumentOutOfRangeException"/> if <paramref name="value"/> is negative.
1013 /// </summary>
1114 /// <param name="value">The argument to validate as non-negative.</param>
1215 /// <param name="paramName">The name of the parameter with which <paramref name="value"/> corresponds.</param>
1316 /// <returns><paramref name="value"/>.</returns>
14- public static int ThrowIfNegative ( this int value
15- #if NETCOREAPP3_0_OR_GREATER
16- , [ CallerArgumentExpression ( nameof ( value ) ) ] string ? paramName = null
17- #endif
18- )
17+ public static int ThrowIfNegative ( this int value , [ CallerArgumentExpression ( nameof ( value ) ) ] string ? paramName = null )
1918 {
2019#if NET8_0_OR_GREATER
2120 ArgumentOutOfRangeException . ThrowIfNegative ( value , paramName ) ;
22- #elif NETCOREAPP3_0_OR_GREATER
21+ #else
2322 if ( value < 0 )
2423 {
2524 throw new ArgumentOutOfRangeException ( paramName , value , $ "{ paramName } ('{ value } ') must be a non-negative value.") ;
2625 }
26+ #endif
27+
28+ return value ;
29+ }
2730#else
31+ /// <summary>
32+ /// Throws an <see cref="ArgumentOutOfRangeException"/> if <paramref name="value"/> is negative.
33+ /// </summary>
34+ /// <param name="value">The argument to validate as non-negative.</param>
35+ /// <returns><paramref name="value"/>.</returns>
36+ public static int ThrowIfNegative ( this int value )
37+ {
2838 if ( value < 0 )
2939 {
40+ #pragma warning disable S3928 // Parameter names used into ArgumentException constructors should match an existing one
3041 throw new ArgumentOutOfRangeException ( null , value , $ " ('{ value } ') must be a non-negative value.") ;
42+ #pragma warning restore S3928 // Parameter names used into ArgumentException constructors should match an existing one
3143 }
32- #endif
3344
3445 return value ;
3546 }
47+ #endif
3648
3749 /// <summary>
3850 /// Determines whether the <see cref="StringSplitOptions.RemoveEmptyEntries"/> bit field is set in the current instance.
@@ -44,6 +56,7 @@ public static bool IsRemoveEmptyEntriesSet(this StringSplitOptions options)
4456 return options . HasFlag ( StringSplitOptions . RemoveEmptyEntries ) ;
4557 }
4658
59+ #if NET5_0_OR_GREATER
4760 /// <summary>
4861 /// Determines whether the <see cref="StringSplitOptions.TrimEntries"/> bit field is set in the current instance.
4962 /// </summary>
@@ -54,11 +67,18 @@ public static bool IsRemoveEmptyEntriesSet(this StringSplitOptions options)
5467 /// <returns><see langword="true"/> if <paramref name="options"/> has the <see cref="StringSplitOptions.TrimEntries"/> bit field set; <see langword="false"/> otherwise.</returns>
5568 public static bool IsTrimEntriesSet ( this StringSplitOptions options )
5669 {
57- #if NET5_0_OR_GREATER
5870 return options . HasFlag ( StringSplitOptions . TrimEntries ) ;
71+ }
5972#else
73+ /// <summary>
74+ /// Always returns false.
75+ /// </summary>
76+ /// <param name="options">The <see cref="StringSplitOptions"/> instance to test.</param>
77+ /// <returns><see langword="false"/>.</returns>
78+ public static bool IsTrimEntriesSet ( this StringSplitOptions options )
79+ {
6080 return false ;
61- #endif
6281 }
82+ #endif
6383 }
6484}
0 commit comments