|
| 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 | +} |
0 commit comments