Skip to content

Commit 901616c

Browse files
ErgamonGeraldLx
andauthored
Removed different method signatures for NETFRAMEWORK and NETSTANDARD2_0 (#338)
Co-authored-by: Gerald Mahlmeister <[email protected]>
1 parent 1051a5b commit 901616c

8 files changed

+5
-272
lines changed

src/GuardClauses/CompilerFixes/CallerArgumentExpressionAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if NETSTANDARD2_1
1+
#if NETFRAMEWORK || NETSTANDARD2_0_OR_GREATER
22

33
namespace System.Runtime.CompilerServices;
44

src/GuardClauses/GuardAgainstExpressionExtensions.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ public static T Expression<T>(this IGuardClause guardClause,
2323
Func<T, bool> func,
2424
T input,
2525
string message,
26-
#if NET7_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
27-
[CallerArgumentExpression("input")]
28-
#endif
29-
string? parameterName = null) where T : struct
26+
[CallerArgumentExpression("input")] string? parameterName = null)
27+
where T : struct
3028
{
3129
if (func(input))
3230
{
@@ -53,10 +51,8 @@ public static async Task<T> ExpressionAsync<T>(this IGuardClause guardClause,
5351
Func<T, Task<bool>> func,
5452
T input,
5553
string message,
56-
#if NET7_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
57-
[CallerArgumentExpression("input")]
58-
#endif
59-
string? parameterName = null) where T : struct
54+
[CallerArgumentExpression("input")] string? parameterName = null)
55+
where T : struct
6056
{
6157
if (await func(input))
6258
{

src/GuardClauses/GuardAgainstNegativeExtensions.cs

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,10 @@ public static partial class GuardClauseExtensions
1414
/// <param name="message">Optional. Custom error message</param>
1515
/// <returns><paramref name="input" /> if the value is not negative.</returns>
1616
/// <exception cref="ArgumentException"></exception>
17-
#if NETFRAMEWORK || NETSTANDARD2_0
18-
public static int Negative(this IGuardClause guardClause,
19-
int input,
20-
string parameterName,
21-
string? message = null)
22-
#else
2317
public static int Negative(this IGuardClause guardClause,
2418
int input,
2519
[CallerArgumentExpression("input")] string? parameterName = null,
2620
string? message = null)
27-
#endif
2821
{
2922
return Negative<int>(guardClause, input, parameterName, message);
3023
}
@@ -38,17 +31,10 @@ public static int Negative(this IGuardClause guardClause,
3831
/// <param name="message">Optional. Custom error message</param>
3932
/// <returns><paramref name="input" /> if the value is not negative.</returns>
4033
/// <exception cref="ArgumentException"></exception>
41-
#if NETFRAMEWORK || NETSTANDARD2_0
42-
public static long Negative(this IGuardClause guardClause,
43-
long input,
44-
string parameterName,
45-
string? message = null)
46-
#else
4734
public static long Negative(this IGuardClause guardClause,
4835
long input,
4936
[CallerArgumentExpression("input")] string? parameterName = null,
5037
string? message = null)
51-
#endif
5238
{
5339
return Negative<long>(guardClause, input, parameterName, message);
5440
}
@@ -62,17 +48,10 @@ public static long Negative(this IGuardClause guardClause,
6248
/// <param name="message">Optional. Custom error message</param>
6349
/// <returns><paramref name="input" /> if the value is not negative.</returns>
6450
/// <exception cref="ArgumentException"></exception>
65-
#if NETFRAMEWORK || NETSTANDARD2_0
66-
public static decimal Negative(this IGuardClause guardClause,
67-
decimal input,
68-
string parameterName,
69-
string? message = null)
70-
#else
7151
public static decimal Negative(this IGuardClause guardClause,
7252
decimal input,
7353
[CallerArgumentExpression("input")] string? parameterName = null,
7454
string? message = null)
75-
#endif
7655
{
7756
return Negative<decimal>(guardClause, input, parameterName, message);
7857
}
@@ -86,17 +65,10 @@ public static decimal Negative(this IGuardClause guardClause,
8665
/// <param name="message">Optional. Custom error message</param>
8766
/// <returns><paramref name="input" /> if the value is not negative.</returns>
8867
/// <exception cref="ArgumentException"></exception>
89-
#if NETFRAMEWORK || NETSTANDARD2_0
90-
public static float Negative(IGuardClause guardClause,
91-
float input,
92-
string parameterName,
93-
string? message = null)
94-
#else
9568
public static float Negative(this IGuardClause guardClause,
9669
float input,
9770
[CallerArgumentExpression("input")] string? parameterName = null,
9871
string? message = null)
99-
#endif
10072
{
10173
return Negative<float>(guardClause, input, parameterName, message);
10274
}
@@ -110,17 +82,10 @@ public static float Negative(this IGuardClause guardClause,
11082
/// <param name="message">Optional. Custom error message</param>
11183
/// <returns><paramref name="input" /> if the value is not negative.</returns>
11284
/// <exception cref="ArgumentException"></exception>
113-
#if NETFRAMEWORK || NETSTANDARD2_0
114-
public static double Negative(this IGuardClause guardClause,
115-
double input,
116-
string parameterName,
117-
string? message = null)
118-
#else
11985
public static double Negative(this IGuardClause guardClause,
12086
double input,
12187
[CallerArgumentExpression("input")] string? parameterName = null,
12288
string? message = null)
123-
#endif
12489
{
12590
return Negative<double>(guardClause, input, parameterName, message);
12691
}
@@ -134,17 +99,10 @@ public static double Negative(this IGuardClause guardClause,
13499
/// <param name="message">Optional. Custom error message</param>
135100
/// <returns><paramref name="input" /> if the value is not negative.</returns>
136101
/// <exception cref="ArgumentException"></exception>
137-
#if NETFRAMEWORK || NETSTANDARD2_0
138-
public static TimeSpan Negative(this IGuardClause guardClause,
139-
TimeSpan input,
140-
string parameterName,
141-
string? message = null)
142-
#else
143102
public static TimeSpan Negative(this IGuardClause guardClause,
144103
TimeSpan input,
145104
[CallerArgumentExpression("input")] string? parameterName = null,
146105
string? message = null)
147-
#endif
148106
{
149107
return Negative<TimeSpan>(guardClause, input, parameterName, message);
150108
}
@@ -158,17 +116,10 @@ public static TimeSpan Negative(this IGuardClause guardClause,
158116
/// <param name="message">Optional. Custom error message</param>
159117
/// <returns><paramref name="input" /> if the value is not negative.</returns>
160118
/// <exception cref="ArgumentException"></exception>
161-
#if NETFRAMEWORK || NETSTANDARD2_0
162-
private static T Negative<T>(this IGuardClause guardClause,
163-
T input,
164-
string parameterName,
165-
string? message = null) where T : struct, IComparable
166-
#else
167119
private static T Negative<T>(this IGuardClause guardClause,
168120
T input,
169121
[CallerArgumentExpression("input")] string? parameterName = null,
170122
string? message = null) where T : struct, IComparable
171-
#endif
172123
{
173124
if (input.CompareTo(default(T)) < 0)
174125
{
@@ -186,17 +137,10 @@ private static T Negative<T>(this IGuardClause guardClause,
186137
/// <param name="parameterName"></param>
187138
/// <param name="message">Optional. Custom error message</param>
188139
/// <returns><paramref name="input" /> if the value is not negative or zero.</returns>
189-
#if NETFRAMEWORK || NETSTANDARD2_0
190-
public static int NegativeOrZero(this IGuardClause guardClause,
191-
int input,
192-
string parameterName,
193-
string? message = null)
194-
#else
195140
public static int NegativeOrZero(this IGuardClause guardClause,
196141
int input,
197142
[CallerArgumentExpression("input")] string? parameterName = null,
198143
string? message = null)
199-
#endif
200144
{
201145
return NegativeOrZero<int>(guardClause, input, parameterName, message);
202146
}
@@ -209,17 +153,10 @@ public static int NegativeOrZero(this IGuardClause guardClause,
209153
/// <param name="parameterName"></param>
210154
/// <param name="message">Optional. Custom error message</param>
211155
/// <returns><paramref name="input" /> if the value is not negative or zero.</returns>
212-
#if NETFRAMEWORK || NETSTANDARD2_0
213-
public static long NegativeOrZero(this IGuardClause guardClause,
214-
long input,
215-
string parameterName,
216-
string? message = null)
217-
#else
218156
public static long NegativeOrZero(this IGuardClause guardClause,
219157
long input,
220158
[CallerArgumentExpression("input")] string? parameterName = null,
221159
string? message = null)
222-
#endif
223160
{
224161
return NegativeOrZero<long>(guardClause, input, parameterName, message);
225162
}
@@ -232,17 +169,10 @@ public static long NegativeOrZero(this IGuardClause guardClause,
232169
/// <param name="parameterName"></param>
233170
/// <param name="message">Optional. Custom error message</param>
234171
/// <returns><paramref name="input" /> if the value is not negative or zero.</returns>
235-
#if NETFRAMEWORK || NETSTANDARD2_0
236-
public static decimal NegativeOrZero(this IGuardClause guardClause,
237-
decimal input,
238-
string parameterName,
239-
string? message = null)
240-
#else
241172
public static decimal NegativeOrZero(this IGuardClause guardClause,
242173
decimal input,
243174
[CallerArgumentExpression("input")] string? parameterName = null,
244175
string? message = null)
245-
#endif
246176
{
247177
return NegativeOrZero<decimal>(guardClause, input, parameterName, message);
248178
}
@@ -255,17 +185,10 @@ public static decimal NegativeOrZero(this IGuardClause guardClause,
255185
/// <param name="parameterName"></param>
256186
/// <param name="message">Optional. Custom error message</param>
257187
/// <returns><paramref name="input" /> if the value is not negative or zero.</returns>
258-
#if NETFRAMEWORK || NETSTANDARD2_0
259-
public static float NegativeOrZero(this IGuardClause guardClause,
260-
float input,
261-
string parameterName,
262-
string? message = null)
263-
#else
264188
public static float NegativeOrZero(this IGuardClause guardClause,
265189
float input,
266190
[CallerArgumentExpression("input")] string? parameterName = null,
267191
string? message = null)
268-
#endif
269192
{
270193
return NegativeOrZero<float>(guardClause, input, parameterName, message);
271194
}
@@ -278,17 +201,10 @@ public static float NegativeOrZero(this IGuardClause guardClause,
278201
/// <param name="parameterName"></param>
279202
/// <param name="message">Optional. Custom error message</param>
280203
/// <returns><paramref name="input" /> if the value is not negative or zero.</returns>
281-
#if NETFRAMEWORK || NETSTANDARD2_0
282-
public static double NegativeOrZero(this IGuardClause guardClause,
283-
double input,
284-
string parameterName,
285-
string? message = null)
286-
#else
287204
public static double NegativeOrZero(this IGuardClause guardClause,
288205
double input,
289206
[CallerArgumentExpression("input")] string? parameterName = null,
290207
string? message = null)
291-
#endif
292208
{
293209
return NegativeOrZero<double>(guardClause, input, parameterName, message);
294210
}
@@ -301,17 +217,10 @@ public static double NegativeOrZero(this IGuardClause guardClause,
301217
/// <param name="parameterName"></param>
302218
/// <param name="message">Optional. Custom error message</param>
303219
/// <returns><paramref name="input" /> if the value is not negative or zero.</returns>
304-
#if NETFRAMEWORK || NETSTANDARD2_0
305-
public static TimeSpan NegativeOrZero(this IGuardClause guardClause,
306-
TimeSpan input,
307-
string parameterName,
308-
string? message = null)
309-
#else
310220
public static TimeSpan NegativeOrZero(this IGuardClause guardClause,
311221
TimeSpan input,
312222
[CallerArgumentExpression("input")] string? parameterName = null,
313223
string? message = null)
314-
#endif
315224
{
316225
return NegativeOrZero<TimeSpan>(guardClause, input, parameterName, message);
317226
}
@@ -325,17 +234,10 @@ public static TimeSpan NegativeOrZero(this IGuardClause guardClause,
325234
/// <param name="parameterName"></param>
326235
/// <param name="message">Optional. Custom error message</param>
327236
/// <returns><paramref name="input" /> if the value is not negative or zero.</returns>
328-
#if NETFRAMEWORK || NETSTANDARD2_0
329-
private static T NegativeOrZero<T>(this IGuardClause guardClause,
330-
T input,
331-
string parameterName,
332-
string? message = null) where T : struct, IComparable
333-
#else
334237
private static T NegativeOrZero<T>(this IGuardClause guardClause,
335238
T input,
336239
[CallerArgumentExpression("input")] string? parameterName = null,
337240
string? message = null) where T : struct, IComparable
338-
#endif
339241
{
340242
if (input.CompareTo(default(T)) <= 0)
341243
{

src/GuardClauses/GuardAgainstNotFoundExtensions.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,10 @@ public static partial class GuardClauseExtensions
1515
/// <param name="parameterName"></param>
1616
/// <returns><paramref name="input" /> if the value is not null.</returns>
1717
/// <exception cref="NotFoundException"></exception>
18-
#if NETFRAMEWORK || NETSTANDARD2_0
19-
public static T NotFound<T>(this IGuardClause guardClause,
20-
[NotNull][ValidatedNotNull] string key,
21-
[NotNull][ValidatedNotNull] T? input,
22-
string parameterName)
23-
#else
2418
public static T NotFound<T>(this IGuardClause guardClause,
2519
[NotNull][ValidatedNotNull] string key,
2620
[NotNull][ValidatedNotNull] T? input,
2721
[CallerArgumentExpression("input")] string? parameterName = null)
28-
#endif
2922
{
3023
guardClause.NullOrEmpty(key, nameof(key));
3124

@@ -48,17 +41,10 @@ public static T NotFound<T>(this IGuardClause guardClause,
4841
/// <param name="parameterName"></param>
4942
/// <returns><paramref name="input" /> if the value is not null.</returns>
5043
/// <exception cref="NotFoundException"></exception>
51-
#if NETFRAMEWORK || NETSTANDARD2_0
52-
public static T NotFound<TKey, T>(this IGuardClause guardClause,
53-
[NotNull][ValidatedNotNull] TKey key,
54-
[NotNull][ValidatedNotNull] T? input,
55-
string parameterName) where TKey : struct
56-
#else
5744
public static T NotFound<TKey, T>(this IGuardClause guardClause,
5845
[NotNull][ValidatedNotNull] TKey key,
5946
[NotNull][ValidatedNotNull]T? input,
6047
[CallerArgumentExpression("input")] string? parameterName = null) where TKey : struct
61-
#endif
6248
{
6349
guardClause.Null(key, nameof(key));
6450

0 commit comments

Comments
 (0)