// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; using System.Diagnostics.CodeAnalysis; namespace CommunityToolkit.Diagnostics; /// partial class Guard { /// partial class ThrowHelper { /// /// Throws an when fails. /// [DoesNotReturn] public static void ThrowArgumentExceptionForIsCloseTo(int value, int target, uint delta, string name) { throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(int).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((double)((long)value - target)))}.", name); } /// /// Throws an when fails. /// [DoesNotReturn] public static void ThrowArgumentExceptionForIsNotCloseTo(int value, int target, uint delta, string name) { throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(int).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((double)((long)value - target)))}.", name); } /// /// Throws an when fails. /// [DoesNotReturn] public static void ThrowArgumentExceptionForIsCloseTo(long value, long target, ulong delta, string name) { throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(long).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((decimal)value - target))}.", name); } /// /// Throws an when fails. /// [DoesNotReturn] public static void ThrowArgumentExceptionForIsNotCloseTo(long value, long target, ulong delta, string name) { throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(long).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs((decimal)value - target))}.", name); } /// /// Throws an when fails. /// [DoesNotReturn] public static void ThrowArgumentExceptionForIsCloseTo(float value, float target, float delta, string name) { throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(float).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}.", name); } /// /// Throws an when fails. /// [DoesNotReturn] public static void ThrowArgumentExceptionForIsNotCloseTo(float value, float target, float delta, string name) { throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(float).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}.", name); } /// /// Throws an when fails. /// [DoesNotReturn] public static void ThrowArgumentExceptionForIsCloseTo(double value, double target, double delta, string name) { throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(double).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}.", name); } /// /// Throws an when fails. /// [DoesNotReturn] public static void ThrowArgumentExceptionForIsNotCloseTo(double value, double target, double delta, string name) { throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(double).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}.", name); } /// /// Throws an when fails. /// [DoesNotReturn] public static void ThrowArgumentExceptionForIsCloseTo(nint value, nint target, nuint delta, string name) { throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(nint).ToTypeString()}) must be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}.", name); } /// /// Throws an when fails. /// [DoesNotReturn] public static void ThrowArgumentExceptionForIsNotCloseTo(nint value, nint target, nuint delta, string name) { throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(nint).ToTypeString()}) must not be within a distance of {AssertString(delta)} from {AssertString(target)}, was {AssertString(value)} and had a distance of {AssertString(Math.Abs(value - target))}.", name); } } }