Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit 33581f8

Browse files
committed
Add support for ArgumentOutOfRangeExceptionMadness
1 parent b7c6ff4 commit 33581f8

File tree

5 files changed

+85
-6
lines changed

5 files changed

+85
-6
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>3.15.0</Version>
3+
<Version>3.16.0</Version>
44
</PropertyGroup>
55

66
<PropertyGroup>

JustArchiNET.Madness/ArgumentExceptionMadness/ArgumentException.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ namespace JustArchiNET.Madness.ArgumentExceptionMadness;
3030
[PublicAPI]
3131
public class ArgumentException : System.ArgumentException {
3232
[MadnessType(EMadnessType.Proxy)]
33-
public ArgumentException(string message, string paramName) : base(message, paramName) { }
33+
public ArgumentException(string message, [InvokerParameterName] string paramName) : base(message, paramName) { }
3434

3535
[MadnessType(EMadnessType.Proxy)]
36-
public ArgumentException(string message, string paramName, Exception innerException) : base(message, paramName, innerException) { }
36+
public ArgumentException(string message, [InvokerParameterName] string paramName, Exception innerException) : base(message, paramName, innerException) { }
3737

3838
[MadnessType(EMadnessType.Proxy)]
3939
public ArgumentException(string message, Exception innerException) : base(message, innerException) { }
@@ -52,7 +52,7 @@ public static void ThrowIfNullOrEmpty(
5252
[System.Diagnostics.CodeAnalysis.NotNull]
5353
#endif
5454

55-
string? argument, string? paramName = null
55+
string? argument, [InvokerParameterName] string? paramName = null
5656
) {
5757
if (string.IsNullOrEmpty(argument)) {
5858
ArgumentNullExceptionMadness.ArgumentNullException.ThrowIfNull(argument, paramName);

JustArchiNET.Madness/ArgumentNullExceptionMadness/ArgumentNullException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static void ThrowIfNull<T>(
4646
[System.Diagnostics.CodeAnalysis.NotNull]
4747
#endif
4848

49-
T? argument, string? paramName = null
49+
T? argument, [InvokerParameterName] string? paramName = null
5050
) {
5151
if (argument is null) {
5252
throw new ArgumentNullException(paramName ?? typeof(T).ToString());
@@ -61,7 +61,7 @@ public static void ThrowIfNull(
6161
[System.Diagnostics.CodeAnalysis.NotNull]
6262
#endif
6363

64-
object? argument, string? paramName = null
64+
object? argument, [InvokerParameterName] string? paramName = null
6565
) {
6666
if (argument is not null) {
6767
return;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// _ __ __
2+
// ___ ___ ___ _ __ __| | __ _ | \/ |
3+
// / __|/ __| / _ \| '_ \ / _` | / _` || |\/| |
4+
// \__ \\__ \| __/| | | || (_| || (_| || | | |
5+
// |___/|___/ \___||_| |_| \__,_| \__,_||_| |_|
6+
// |
7+
// Copyright 2021-2023 Łukasz "JustArchi" Domeradzki
8+
// Contact: JustArchi@JustArchi.net
9+
// |
10+
// Licensed under the Apache License, Version 2.0 (the "License");
11+
// you may not use this file except in compliance with the License.
12+
// You may obtain a copy of the License at
13+
// |
14+
// http://www.apache.org/licenses/LICENSE-2.0
15+
// |
16+
// Unless required by applicable law or agreed to in writing, software
17+
// distributed under the License is distributed on an "AS IS" BASIS,
18+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
// See the License for the specific language governing permissions and
20+
// limitations under the License.
21+
22+
using System;
23+
using System.Collections.Generic;
24+
using JetBrains.Annotations;
25+
using JustArchiNET.Madness.Helpers;
26+
27+
namespace JustArchiNET.Madness.ArgumentOutOfRangeExceptionMadness;
28+
29+
[MadnessType(EMadnessType.Replacement)]
30+
[PublicAPI]
31+
public class ArgumentOutOfRangeException : System.ArgumentOutOfRangeException {
32+
[MadnessType(EMadnessType.Proxy)]
33+
public ArgumentOutOfRangeException([InvokerParameterName] string paramName, string message) : base(paramName, message) { }
34+
35+
[MadnessType(EMadnessType.Proxy)]
36+
public ArgumentOutOfRangeException(string message, Exception innerException) : base(message, innerException) { }
37+
38+
[MadnessType(EMadnessType.Proxy)]
39+
public ArgumentOutOfRangeException([InvokerParameterName] string paramName) : base(paramName) { }
40+
41+
[MadnessType(EMadnessType.Proxy)]
42+
public ArgumentOutOfRangeException() { }
43+
44+
[MadnessType(EMadnessType.Implementation)]
45+
public static void ThrowIfEqual<T>(T value, T other, [InvokerParameterName] string? paramName = null) where T : IEquatable<T>? {
46+
if (EqualityComparer<T>.Default.Equals(value, other)) {
47+
throw new ArgumentOutOfRangeException(paramName ?? typeof(T).ToString());
48+
}
49+
}
50+
51+
[MadnessType(EMadnessType.Implementation)]
52+
public static void ThrowIfLessThan<T>(T value, T other, [InvokerParameterName] string? paramName = null) where T : IComparable<T> {
53+
if (value.CompareTo(other) < 0) {
54+
throw new ArgumentOutOfRangeException(paramName ?? typeof(T).ToString());
55+
}
56+
}
57+
58+
[MadnessType(EMadnessType.Implementation)]
59+
public static void ThrowIfNegative<T>(T value, [InvokerParameterName] string? paramName = null) {
60+
if (value is < 0) {
61+
throw new ArgumentOutOfRangeException(paramName ?? typeof(T).ToString());
62+
}
63+
}
64+
65+
[MadnessType(EMadnessType.Implementation)]
66+
public static void ThrowIfNegativeOrZero<T>(T value, [InvokerParameterName] string? paramName = null) {
67+
if (value is <= 0) {
68+
throw new ArgumentOutOfRangeException(paramName ?? typeof(T).ToString());
69+
}
70+
}
71+
72+
[MadnessType(EMadnessType.Implementation)]
73+
public static void ThrowIfZero<T>(T value, [InvokerParameterName] string? paramName = null) {
74+
if (value is 0) {
75+
throw new ArgumentOutOfRangeException(paramName ?? typeof(T).ToString());
76+
}
77+
}
78+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Example:
6363
<Using Include="JustArchiNET.Madness" />
6464
<Using Include="JustArchiNET.Madness.ArgumentExceptionMadness.ArgumentException" Alias="ArgumentException" />
6565
<Using Include="JustArchiNET.Madness.ArgumentNullExceptionMadness.ArgumentNullException" Alias="ArgumentNullException" />
66+
<Using Include="JustArchiNET.Madness.ArgumentOutOfRangeExceptionMadness.ArgumentOutOfRangeException" Alias="ArgumentOutOfRangeException" />
6667
<Using Include="JustArchiNET.Madness.ArrayMadness.Array" Alias="Array" />
6768
<Using Include="JustArchiNET.Madness.ConvertMadness.Convert" Alias="Convert" />
6869
<Using Include="JustArchiNET.Madness.DirectoryInfoMadness.DirectoryInfo" Alias="DirectoryInfo" />

0 commit comments

Comments
 (0)