From b1041ea8dc9e9a589def83e9f5889ac0b651dc44 Mon Sep 17 00:00:00 2001 From: miko Date: Sun, 26 May 2024 21:11:05 +0800 Subject: [PATCH] Fix exception expressions --- .../DefaultValueTests/EncodeNullValueTests.cs | 18 +++++------------- .../Contexts/TupleObjectConverterContext.cs | 4 ++-- .../Attributes/AttributeTests.fs | 8 ++++---- .../Contexts/AllocatorModuleTests.fs | 10 ---------- .../Contexts/AllocatorTests.fs | 2 -- .../Contexts/ConverterTests.fs | 1 - .../Contexts/GeneratorObjectConverterTests.fs | 2 +- .../Contexts/GeneratorTests.fs | 2 +- .../TupleLike/TupleTests.fs | 8 ++++---- .../Contexts/ConverterStaticTests.cs | 2 -- .../Contexts/ConverterStreamTests.cs | 2 -- code/Binary/Allocator.Invoke.cs | 4 ++-- code/Binary/Allocator.Module.cs | 6 ++---- code/Binary/Allocator.cs | 6 ++---- code/Binary/Converter.Static.cs | 6 ++---- code/Binary/Converter.cs | 3 +-- .../GeneratorObjectConverter.cs | 12 +++++++++--- code/Binary/Internal/ThrowHelper.cs | 14 +------------- 18 files changed, 36 insertions(+), 74 deletions(-) diff --git a/code/Binary.SourceGeneration.TupleObjectTests/DefaultValueTests/EncodeNullValueTests.cs b/code/Binary.SourceGeneration.TupleObjectTests/DefaultValueTests/EncodeNullValueTests.cs index 9d7e55e6..83b1f72b 100644 --- a/code/Binary.SourceGeneration.TupleObjectTests/DefaultValueTests/EncodeNullValueTests.cs +++ b/code/Binary.SourceGeneration.TupleObjectTests/DefaultValueTests/EncodeNullValueTests.cs @@ -3,7 +3,6 @@ using Mikodev.Binary.Attributes; using System; using System.Collections.Generic; -using System.Linq; using Xunit; [SourceGeneratorContext] @@ -43,29 +42,22 @@ public void EncodeNullValueTest(T source) where T : class var bufferSecond = converterSecond.Encode(source); Assert.Equal(buffer, bufferSecond); - var a = Assert.Throws(() => converter.Encode(null)); - var b = Assert.Throws(() => converterSecond.Encode(null)); - var c = Assert.Throws(() => + var a = Assert.Throws(() => converter.Encode(null)); + var b = Assert.Throws(() => converterSecond.Encode(null)); + var c = Assert.Throws(() => { var allocator = new Allocator(); converter.EncodeAuto(ref allocator, null); }); - var d = Assert.Throws(() => + var d = Assert.Throws(() => { var allocator = new Allocator(); converterSecond.EncodeAuto(ref allocator, null); }); - var h = Converter.GetMethod(converter, "Encode"); - var i = Converter.GetMethod(converterSecond, "Encode"); - var j = Converter.GetMethod(converter, "EncodeAuto"); - var k = Converter.GetMethod(converterSecond, "EncodeAuto"); var message = $"Tuple can not be null, type: {typeof(T)}"; var exceptions = new[] { a, b, c, d }; - var parameters = new[] { h, i, j, k }.Select(x => x.GetParameters()[1]); - - Assert.All(parameters, x => Assert.Equal("item", x.Name)); - Assert.All(exceptions, x => Assert.Equal("item", x.ParamName)); + Assert.All(exceptions, x => Assert.Null(x.ParamName)); Assert.All(exceptions, x => Assert.StartsWith(message, x.Message)); } } diff --git a/code/Binary.SourceGeneration/Contexts/TupleObjectConverterContext.cs b/code/Binary.SourceGeneration/Contexts/TupleObjectConverterContext.cs index 91fc76dc..0575efa2 100644 --- a/code/Binary.SourceGeneration/Contexts/TupleObjectConverterContext.cs +++ b/code/Binary.SourceGeneration/Contexts/TupleObjectConverterContext.cs @@ -37,10 +37,10 @@ private void AppendExceptMethod() { if (Symbol.IsValueType) return; - Output.AppendIndent(2, $"[System.Diagnostics.CodeAnalysis.DoesNotReturn]"); + Output.AppendIndent(2, $"[System.Diagnostics.DebuggerStepThrough, System.Diagnostics.CodeAnalysis.DoesNotReturn]"); Output.AppendIndent(2, $"private static void Except()"); Output.AppendIndent(2, $"{{"); - Output.AppendIndent(3, $"throw new System.ArgumentNullException(\"item\", $\"Tuple can not be null, type: {{typeof({SymbolTypeFullName})}}\");"); + Output.AppendIndent(3, $"throw new System.ArgumentException($\"Tuple can not be null, type: {{typeof({SymbolTypeFullName})}}\");"); Output.AppendIndent(2, $"}}"); Output.AppendIndent(); CancellationToken.ThrowIfCancellationRequested(); diff --git a/code/Binary.Tests.FSharp/Attributes/AttributeTests.fs b/code/Binary.Tests.FSharp/Attributes/AttributeTests.fs index 4e69d2f4..ef998608 100644 --- a/code/Binary.Tests.FSharp/Attributes/AttributeTests.fs +++ b/code/Binary.Tests.FSharp/Attributes/AttributeTests.fs @@ -820,12 +820,12 @@ type AttributeTests() = [)>] member __.``Tuple Object Null`` (t : Type) = let converter = generator.GetConverter t |> box :?> IConverter - let alpha = Assert.Throws(fun () -> let mutable allocator = Allocator() in converter.Encode(&allocator, null)) - let bravo = Assert.Throws(fun () -> converter.Encode null |> ignore) + let alpha = Assert.Throws(fun () -> let mutable allocator = Allocator() in converter.Encode(&allocator, null)) + let bravo = Assert.Throws(fun () -> converter.Encode null |> ignore) let message = sprintf "Tuple can not be null, type: %O" t - Assert.Equal("item", alpha.ParamName) + Assert.Null(alpha.ParamName) Assert.StartsWith(message, alpha.Message) - Assert.Equal("item", bravo.ParamName) + Assert.Null(bravo.ParamName) Assert.StartsWith(message, bravo.Message) () diff --git a/code/Binary.Tests.FSharp/Contexts/AllocatorModuleTests.fs b/code/Binary.Tests.FSharp/Contexts/AllocatorModuleTests.fs index d388ae0d..9769dfe3 100644 --- a/code/Binary.Tests.FSharp/Contexts/AllocatorModuleTests.fs +++ b/code/Binary.Tests.FSharp/Contexts/AllocatorModuleTests.fs @@ -47,7 +47,6 @@ let ``Append Action (default constructor, length invalid)`` (length : int) = let methodInfos = allocatorType.GetMethods() |> Array.filter (fun x -> x.Name = "Append" && x.GetParameters().Length = 4) let methodInfo = methodInfos |> Array.filter (fun x -> x.GetParameters().[3].ParameterType.Name.StartsWith "SpanAction`2") |> Array.exactlyOne let parameter = methodInfo.GetParameters().[1] - Assert.StartsWith("Argument length must be greater than or equal to zero!", error.Message) Assert.Equal("length", error.ParamName) Assert.Equal("length", parameter.Name) () @@ -64,7 +63,6 @@ let ``Append Max Length (default constructor, max length invalid)`` (maxLength : let methodInfos = allocatorType.GetMethods() |> Array.filter (fun x -> x.Name = "Append" && x.GetParameters().Length = 4) let methodInfo = methodInfos |> Array.filter (fun x -> x.GetParameters().[3].ParameterType.Name.StartsWith "AllocatorWriter`1") |> Array.exactlyOne let parameter = methodInfo.GetParameters().[1] - Assert.StartsWith("Argument max length must be greater than or equal to zero!", error.Message) Assert.Equal("maxLength", error.ParamName) Assert.Equal("maxLength", parameter.Name) () @@ -81,7 +79,6 @@ let ``Append Max Length With Length Prefix (default constructor, max length inva let methodInfos = allocatorType.GetMethods() |> Array.filter (fun x -> x.Name = "AppendWithLengthPrefix" && x.GetParameters().Length = 4) let methodInfo = methodInfos |> Array.filter (fun x -> x.GetParameters().[3].ParameterType.Name.StartsWith "AllocatorWriter`1") |> Array.exactlyOne let parameter = methodInfo.GetParameters().[1] - Assert.StartsWith("Argument max length must be greater than or equal to zero!", error.Message) Assert.Equal("maxLength", error.ParamName) Assert.Equal("maxLength", parameter.Name) () @@ -92,7 +89,6 @@ let ``Append Action (default constructor, length overflow)`` () = let mutable allocator = Allocator() Allocator.Append(&allocator, Int32.MaxValue + 1, null :> obj, fun a b -> raise (NotSupportedException()); ()) ()) - Assert.StartsWith("Argument length must be greater than or equal to zero!", error.Message) Assert.Equal("length", error.ParamName) () @@ -102,7 +98,6 @@ let ``Append Max Length (default constructor, max length overflow)`` () = let mutable allocator = Allocator() Allocator.Append(&allocator, Int32.MaxValue + 1, null :> obj, fun a b -> raise (NotSupportedException()); -1) ()) - Assert.StartsWith("Argument max length must be greater than or equal to zero!", error.Message) Assert.Equal("maxLength", error.ParamName) () @@ -112,7 +107,6 @@ let ``Append Max Length With Length Prefix (default constructor, max length over let mutable allocator = Allocator() Allocator.AppendWithLengthPrefix(&allocator, Int32.MaxValue + 1, null :> obj, fun a b -> raise (NotSupportedException()); -1) ()) - Assert.StartsWith("Argument max length must be greater than or equal to zero!", error.Message) Assert.Equal("maxLength", error.ParamName) () @@ -162,7 +156,6 @@ let ``Append Action (append some then, length invalid)`` (length : int) = Allocator.Append(&allocator, length, null :> obj, fun a b -> raise (NotSupportedException()); ()) ()) Assert.Equal(1, flag) - Assert.StartsWith("Argument length must be greater than or equal to zero!", error.Message) Assert.Equal("length", error.ParamName) () @@ -179,7 +172,6 @@ let ``Append Max Length (append some then, max length invalid)`` (maxLength : in Allocator.Append(&allocator, maxLength, null :> obj, fun a b -> raise (NotSupportedException()); -1) ()) Assert.Equal(1, flag) - Assert.StartsWith("Argument max length must be greater than or equal to zero!", error.Message) Assert.Equal("maxLength", error.ParamName) () @@ -196,7 +188,6 @@ let ``Append Max Length With Length Prefix (append some then, max length invalid Allocator.AppendWithLengthPrefix(&allocator, maxLength, null :> obj, fun a b -> raise (NotSupportedException()); -1) ()) Assert.Equal(1, flag) - Assert.StartsWith("Argument max length must be greater than or equal to zero!", error.Message) Assert.Equal("maxLength", error.ParamName) () @@ -444,7 +435,6 @@ let ``Ensure (negative)`` (maxCapacity : int, offset : int, length : int) = let parameter = methodInfo.GetParameters() |> Array.last Assert.Equal("length", parameter.Name) Assert.Equal("length", error.ParamName) - Assert.StartsWith("Argument length must be greater than or equal to zero!", error.Message) () [] diff --git a/code/Binary.Tests.FSharp/Contexts/AllocatorTests.fs b/code/Binary.Tests.FSharp/Contexts/AllocatorTests.fs index a4486c0f..f301b0f3 100644 --- a/code/Binary.Tests.FSharp/Contexts/AllocatorTests.fs +++ b/code/Binary.Tests.FSharp/Contexts/AllocatorTests.fs @@ -27,8 +27,6 @@ let ``Constructor (argument out of range)`` (limits : int) = Assert.Equal("maxCapacity", parameterName) Assert.Equal("maxCapacity", a.ParamName) Assert.Equal("maxCapacity", b.ParamName) - Assert.StartsWith("Argument max capacity must be greater than or equal to zero!", a.Message) - Assert.StartsWith("Argument max capacity must be greater than or equal to zero!", b.Message) () [] diff --git a/code/Binary.Tests.FSharp/Contexts/ConverterTests.fs b/code/Binary.Tests.FSharp/Contexts/ConverterTests.fs index 0a5b6367..a106d9c1 100644 --- a/code/Binary.Tests.FSharp/Contexts/ConverterTests.fs +++ b/code/Binary.Tests.FSharp/Contexts/ConverterTests.fs @@ -175,7 +175,6 @@ type ConverterTests() = let error = Assert.Throws(fun () -> CustomConverter(length) |> ignore) Assert.Equal("length", parameter.Name) Assert.Equal("length", error.ParamName) - Assert.StartsWith("Argument length must be greater than or equal to zero!", error.Message) () [] diff --git a/code/Binary.Tests.FSharp/Contexts/GeneratorObjectConverterTests.fs b/code/Binary.Tests.FSharp/Contexts/GeneratorObjectConverterTests.fs index cbeeed3d..724a0b46 100644 --- a/code/Binary.Tests.FSharp/Contexts/GeneratorObjectConverterTests.fs +++ b/code/Binary.Tests.FSharp/Contexts/GeneratorObjectConverterTests.fs @@ -102,7 +102,7 @@ type GeneratorObjectConverterTests() = [] [] member __.``Encode Object Instance`` (action : Action, _ : string) = - let error = Assert.Throws(fun () -> action.Invoke(obj())) + let error = Assert.Throws(fun () -> action.Invoke(obj())) let message = "Can not encode object, type: System.Object" Assert.Equal(message, error.Message) () diff --git a/code/Binary.Tests.FSharp/Contexts/GeneratorTests.fs b/code/Binary.Tests.FSharp/Contexts/GeneratorTests.fs index cfe29cc3..1fbb03d9 100644 --- a/code/Binary.Tests.FSharp/Contexts/GeneratorTests.fs +++ b/code/Binary.Tests.FSharp/Contexts/GeneratorTests.fs @@ -112,7 +112,7 @@ let ``Get Converter (non-generic collection)`` () = [] let ``Encode (obj, instance)`` () = let source = obj() - let error = Assert.Throws(fun () -> generator.Encode source |> ignore) + let error = Assert.Throws(fun () -> generator.Encode source |> ignore) Assert.Equal("Can not encode object, type: System.Object", error.Message) () diff --git a/code/Binary.Tests.FSharp/TupleLike/TupleTests.fs b/code/Binary.Tests.FSharp/TupleLike/TupleTests.fs index b7618c38..371e11ce 100644 --- a/code/Binary.Tests.FSharp/TupleLike/TupleTests.fs +++ b/code/Binary.Tests.FSharp/TupleLike/TupleTests.fs @@ -33,11 +33,11 @@ let TestNull<'T> () = let value = Unchecked.defaultof<'T> let converter = generator.GetConverter<'T> () let message = sprintf "Tuple can not be null, type: %O" typeof<'T> - let alpha = Assert.Throws(fun () -> let mutable allocator = Allocator() in converter.Encode(&allocator, value)) - Assert.Equal("item", alpha.ParamName) + let alpha = Assert.Throws(fun () -> let mutable allocator = Allocator() in converter.Encode(&allocator, value)) + Assert.Null(alpha.ParamName) Assert.StartsWith(message, alpha.Message) - let bravo = Assert.Throws(fun () -> let mutable allocator = Allocator() in converter.EncodeAuto(&allocator, value)) - Assert.Equal("item", bravo.ParamName) + let bravo = Assert.Throws(fun () -> let mutable allocator = Allocator() in converter.EncodeAuto(&allocator, value)) + Assert.Null(bravo.ParamName) Assert.StartsWith(message, bravo.Message) () diff --git a/code/Binary.Tests/Contexts/ConverterStaticTests.cs b/code/Binary.Tests/Contexts/ConverterStaticTests.cs index e9e67d13..61a8571e 100644 --- a/code/Binary.Tests/Contexts/ConverterStaticTests.cs +++ b/code/Binary.Tests/Contexts/ConverterStaticTests.cs @@ -32,7 +32,6 @@ public void EncodeByAllocatorOverflowTest(int number) var parameters = method.GetParameters(); Assert.Equal("number", error.ParamName); Assert.Equal("number", parameters[1].Name); - Assert.StartsWith("Argument number must be greater than or equal to zero!", error.Message); } private delegate void Write(Span span, int number, out int written); @@ -47,7 +46,6 @@ public void EncodeBySpanOverflowTest(int number) var parameters = method.GetParameters(); Assert.Equal("number", error.ParamName); Assert.Equal("number", parameters[1].Name); - Assert.StartsWith("Argument number must be greater than or equal to zero!", error.Message); } [Theory(DisplayName = "Encode Decode Integration Test")] diff --git a/code/Binary.Tests/Contexts/ConverterStreamTests.cs b/code/Binary.Tests/Contexts/ConverterStreamTests.cs index 25c50451..c1bad8a8 100644 --- a/code/Binary.Tests/Contexts/ConverterStreamTests.cs +++ b/code/Binary.Tests/Contexts/ConverterStreamTests.cs @@ -64,7 +64,6 @@ public void EncodeInvalidNumberTest(int number) var parameters = method.GetParameters(); Assert.Equal("number", error.ParamName); Assert.Equal("number", parameters[1].Name); - Assert.StartsWith("Argument number must be greater than or equal to zero!", error.Message); } [Theory(DisplayName = "Encode Invalid Number Async")] @@ -80,7 +79,6 @@ public async Task EncodeInvalidNumberTestAsync(int number) var parameters = method.GetParameters(); Assert.Equal("number", error.ParamName); Assert.Equal("number", parameters[1].Name); - Assert.StartsWith("Argument number must be greater than or equal to zero!", error.Message); } private class TestStream : Stream diff --git a/code/Binary/Allocator.Invoke.cs b/code/Binary/Allocator.Invoke.cs index bc0a4871..570b4573 100644 --- a/code/Binary/Allocator.Invoke.cs +++ b/code/Binary/Allocator.Invoke.cs @@ -1,6 +1,7 @@ namespace Mikodev.Binary; using Mikodev.Binary.Internal; +using System; using System.Diagnostics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -9,8 +10,7 @@ public ref partial struct Allocator { private static void Resize(ref Allocator allocator, int length) { - if (length <= 0) - ThrowHelper.ThrowLengthNegative(); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(length); var offset = allocator.offset; Debug.Assert(offset >= 0); var limits = allocator.MaxCapacity; diff --git a/code/Binary/Allocator.Module.cs b/code/Binary/Allocator.Module.cs index b0d9f26f..07c9673d 100644 --- a/code/Binary/Allocator.Module.cs +++ b/code/Binary/Allocator.Module.cs @@ -35,8 +35,7 @@ public static void Append(ref Allocator allocator, int length, T data, SpanAc public static void Append(ref Allocator allocator, int maxLength, T data, AllocatorWriter writer) { ArgumentNullException.ThrowIfNull(writer); - if (maxLength < 0) - ThrowHelper.ThrowMaxLengthNegative(); + ArgumentOutOfRangeException.ThrowIfNegative(maxLength); if (maxLength is 0) return; ref var target = ref Create(ref allocator, maxLength); @@ -51,8 +50,7 @@ public static void Append(ref Allocator allocator, int maxLength, T data, All public static void AppendWithLengthPrefix(ref Allocator allocator, int maxLength, T data, AllocatorWriter writer) { ArgumentNullException.ThrowIfNull(writer); - if (maxLength < 0) - ThrowHelper.ThrowMaxLengthNegative(); + ArgumentOutOfRangeException.ThrowIfNegative(maxLength); var numberLength = NumberModule.EncodeLength((uint)maxLength); ref var target = ref Create(ref allocator, maxLength + numberLength); var actual = maxLength is 0 ? 0 : writer.Invoke(MemoryMarshal.CreateSpan(ref Unsafe.Add(ref target, numberLength), maxLength), data); diff --git a/code/Binary/Allocator.cs b/code/Binary/Allocator.cs index 5f94ab86..041b15dd 100644 --- a/code/Binary/Allocator.cs +++ b/code/Binary/Allocator.cs @@ -39,8 +39,7 @@ public Allocator(Span span) [MethodImpl(MethodImplOptions.AggressiveInlining)] public Allocator(Span span, int maxCapacity) { - if (maxCapacity < 0) - ThrowHelper.ThrowMaxCapacityNegative(); + ArgumentOutOfRangeException.ThrowIfNegative(maxCapacity); this.underlying = null; this.target = ref MemoryMarshal.GetReference(span); this.bounds = Math.Min(span.Length, maxCapacity); @@ -63,8 +62,7 @@ public Allocator(IAllocator underlyingAllocator) public Allocator(IAllocator underlyingAllocator, int maxCapacity) { ArgumentNullException.ThrowIfNull(underlyingAllocator); - if (maxCapacity < 0) - ThrowHelper.ThrowMaxCapacityNegative(); + ArgumentOutOfRangeException.ThrowIfNegative(maxCapacity); this.underlying = underlyingAllocator; this.target = ref Unsafe.NullRef(); this.bounds = 0; diff --git a/code/Binary/Converter.Static.cs b/code/Binary/Converter.Static.cs index 2689142c..ec89d11a 100644 --- a/code/Binary/Converter.Static.cs +++ b/code/Binary/Converter.Static.cs @@ -28,8 +28,7 @@ public static MethodInfo GetMethod(IConverter converter, string name) public static void Encode(scoped Span span, int number, out int bytesWritten) { - if (number < 0) - ThrowHelper.ThrowNumberNegative(); + ArgumentOutOfRangeException.ThrowIfNegative(number); var numberLength = NumberModule.EncodeLength((uint)number); if (span.Length < numberLength) ThrowHelper.ThrowNotEnoughBytesToWrite(); @@ -49,8 +48,7 @@ public static int Decode(scoped ReadOnlySpan span, out int bytesRead) public static void Encode(ref Allocator allocator, int number) { - if (number < 0) - ThrowHelper.ThrowNumberNegative(); + ArgumentOutOfRangeException.ThrowIfNegative(number); var numberLength = NumberModule.EncodeLength((uint)number); NumberModule.Encode(ref Allocator.Assign(ref allocator, numberLength), (uint)number, numberLength); } diff --git a/code/Binary/Converter.cs b/code/Binary/Converter.cs index 686eb0bc..69d1aee6 100644 --- a/code/Binary/Converter.cs +++ b/code/Binary/Converter.cs @@ -18,8 +18,7 @@ protected Converter() : this(0) { } protected Converter(int length) { - if (length < 0) - ThrowHelper.ThrowLengthNegative(); + ArgumentOutOfRangeException.ThrowIfNegative(length); var parent = typeof(Converter); if (new DecodeDelegate(DecodeAuto).Method.DeclaringType == parent && new DecodeDelegate(DecodeWithLengthPrefix).Method.DeclaringType != parent) ThrowHelper.ThrowNotOverride(nameof(DecodeAuto), nameof(DecodeWithLengthPrefix), GetType()); diff --git a/code/Binary/Internal.Contexts/GeneratorObjectConverter.cs b/code/Binary/Internal.Contexts/GeneratorObjectConverter.cs index d9d80cd1..a7d9d83d 100644 --- a/code/Binary/Internal.Contexts/GeneratorObjectConverter.cs +++ b/code/Binary/Internal.Contexts/GeneratorObjectConverter.cs @@ -10,10 +10,16 @@ internal sealed class GeneratorObjectConverter(IGenerator generator) : Converter private readonly IGenerator generator = generator; [DebuggerStepThrough, DoesNotReturn] - private static void ExceptNull() => throw new ArgumentException("Can not get type of null object."); + private static void ExceptNull() + { + throw new ArgumentException("Can not get type of null object."); + } [DebuggerStepThrough, DoesNotReturn] - private static void ExceptEncode() => throw new NotSupportedException($"Can not encode object, type: {typeof(object)}"); + private static void ExceptType() + { + throw new ArgumentException($"Can not encode object, type: {typeof(object)}"); + } private IConverter Ensure(object? item) { @@ -21,7 +27,7 @@ private IConverter Ensure(object? item) ExceptNull(); var type = item.GetType(); if (type == typeof(object)) - ExceptEncode(); + ExceptType(); RuntimeHelpers.EnsureSufficientExecutionStack(); return this.generator.GetConverter(type); } diff --git a/code/Binary/Internal/ThrowHelper.cs b/code/Binary/Internal/ThrowHelper.cs index 80702421..f73433ce 100644 --- a/code/Binary/Internal/ThrowHelper.cs +++ b/code/Binary/Internal/ThrowHelper.cs @@ -10,18 +10,6 @@ internal static class ThrowHelper [DoesNotReturn] internal static void ThrowAllocatorInvalid() => throw new InvalidOperationException("Allocator has been modified unexpectedly!"); - [DoesNotReturn] - internal static void ThrowLengthNegative() => throw new ArgumentOutOfRangeException("length", "Argument length must be greater than or equal to zero!"); - - [DoesNotReturn] - internal static void ThrowNumberNegative() => throw new ArgumentOutOfRangeException("number", "Argument number must be greater than or equal to zero!"); - - [DoesNotReturn] - internal static void ThrowMaxLengthNegative() => throw new ArgumentOutOfRangeException("maxLength", "Argument max length must be greater than or equal to zero!"); - - [DoesNotReturn] - internal static void ThrowMaxCapacityNegative() => throw new ArgumentOutOfRangeException("maxCapacity", "Argument max capacity must be greater than or equal to zero!"); - [DoesNotReturn] internal static void ThrowMaxCapacityOverflow() => throw new ArgumentException("Maximum capacity has been reached."); @@ -29,7 +17,7 @@ internal static class ThrowHelper internal static void ThrowInvalidReturnValue() => throw new InvalidOperationException("Invalid return value."); [DoesNotReturn] - internal static void ThrowTupleNull() => throw new ArgumentNullException("item", $"Tuple can not be null, type: {typeof(T)}"); + internal static void ThrowTupleNull() => throw new ArgumentException($"Tuple can not be null, type: {typeof(T)}"); [DoesNotReturn] internal static void ThrowNotEnoughBytesCollection(int byteLength) => throw new ArgumentException($"Not enough bytes for collection element, byte length: {byteLength}, element type: {typeof(T)}");