From 4ea26c504c6601e60389c0f1d2137d4396d56037 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 14 Jun 2020 20:42:13 +0200 Subject: [PATCH 01/19] Added missing attributes/annotations --- .../Enumerables/ReadOnlySpanEnumerable{T}.cs | 6 ++++-- .../Enumerables/ReadOnlySpanTokenizer{T}.cs | 6 ++++-- .../Enumerables/SpanEnumerable{T}.cs | 6 ++++-- .../Enumerables/SpanTokenizer{T}.cs | 6 ++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanEnumerable{T}.cs b/Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanEnumerable{T}.cs index 29d42924536..c732861d670 100644 --- a/Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanEnumerable{T}.cs +++ b/Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanEnumerable{T}.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -42,8 +43,9 @@ public ReadOnlySpanEnumerable(ReadOnlySpan span) /// Implements the duck-typed method. /// /// An instance targeting the current value. + [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlySpanEnumerable GetEnumerator() => this; + public readonly ReadOnlySpanEnumerable GetEnumerator() => this; /// /// Implements the duck-typed method. @@ -67,7 +69,7 @@ public bool MoveNext() /// /// Gets the duck-typed property. /// - public Item Current + public readonly Item Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get diff --git a/Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanTokenizer{T}.cs b/Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanTokenizer{T}.cs index 3977f5829f8..37bc6168f10 100644 --- a/Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanTokenizer{T}.cs +++ b/Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanTokenizer{T}.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; namespace Microsoft.Toolkit.HighPerformance.Enumerables @@ -54,8 +55,9 @@ public ReadOnlySpanTokenizer(ReadOnlySpan span, T separator) /// Implements the duck-typed method. /// /// An instance targeting the current value. + [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlySpanTokenizer GetEnumerator() => this; + public readonly ReadOnlySpanTokenizer GetEnumerator() => this; /// /// Implements the duck-typed method. @@ -94,7 +96,7 @@ public bool MoveNext() /// /// Gets the duck-typed property. /// - public ReadOnlySpan Current + public readonly ReadOnlySpan Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => this.span.Slice(this.start, this.end - this.start); diff --git a/Microsoft.Toolkit.HighPerformance/Enumerables/SpanEnumerable{T}.cs b/Microsoft.Toolkit.HighPerformance/Enumerables/SpanEnumerable{T}.cs index 791f509339d..3648a5e5140 100644 --- a/Microsoft.Toolkit.HighPerformance/Enumerables/SpanEnumerable{T}.cs +++ b/Microsoft.Toolkit.HighPerformance/Enumerables/SpanEnumerable{T}.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -42,8 +43,9 @@ public SpanEnumerable(Span span) /// Implements the duck-typed method. /// /// An instance targeting the current value. + [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanEnumerable GetEnumerator() => this; + public readonly SpanEnumerable GetEnumerator() => this; /// /// Implements the duck-typed method. @@ -67,7 +69,7 @@ public bool MoveNext() /// /// Gets the duck-typed property. /// - public Item Current + public readonly Item Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get diff --git a/Microsoft.Toolkit.HighPerformance/Enumerables/SpanTokenizer{T}.cs b/Microsoft.Toolkit.HighPerformance/Enumerables/SpanTokenizer{T}.cs index 953eb535f0b..da8a9dce040 100644 --- a/Microsoft.Toolkit.HighPerformance/Enumerables/SpanTokenizer{T}.cs +++ b/Microsoft.Toolkit.HighPerformance/Enumerables/SpanTokenizer{T}.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; namespace Microsoft.Toolkit.HighPerformance.Enumerables @@ -54,8 +55,9 @@ public SpanTokenizer(Span span, T separator) /// Implements the duck-typed method. /// /// An instance targeting the current value. + [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public SpanTokenizer GetEnumerator() => this; + public readonly SpanTokenizer GetEnumerator() => this; /// /// Implements the duck-typed method. @@ -94,7 +96,7 @@ public bool MoveNext() /// /// Gets the duck-typed property. /// - public Span Current + public readonly Span Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => this.span.Slice(this.start, this.end - this.start); From ee8c71cba218e912e864fb014261c08607658125 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 14 Jun 2020 20:46:32 +0200 Subject: [PATCH 02/19] Initial update on ThrowHelper visibility --- .../Generated/ThrowHelper.Collection.g.cs | 178 +++++++++--------- .../Generated/ThrowHelper.Collection.tt | 24 +-- .../ThrowHelper.Collection.Generic.cs | 8 +- .../ThrowHelper.Comparable.Generic.cs | 30 +-- .../ThrowHelper.Comparable.Numeric.cs | 18 +- .../Diagnostics/ThrowHelper.IO.cs | 10 +- .../Diagnostics/ThrowHelper.String.cs | 38 ++-- .../Diagnostics/ThrowHelper.Tasks.cs | 22 +-- .../ThrowHelper.ThrowExceptions.cs | 8 +- Microsoft.Toolkit/Diagnostics/ThrowHelper.cs | 38 ++-- 10 files changed, 187 insertions(+), 187 deletions(-) diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs index b0df73a80e3..d104090bb41 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs @@ -18,14 +18,14 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { /// /// Throws an when (or an overload) fails. /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(Span span, string name) + internal static void ThrowArgumentExceptionForIsEmpty(Span span, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must be empty, had a size of {span.Length.ToAssertString()}"); } @@ -35,7 +35,7 @@ public static void ThrowArgumentExceptionForIsEmpty(Span span, string name /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(Span span, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size equal to {size}, had a size of {span.Length.ToAssertString()}"); } @@ -45,7 +45,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(Span span, int /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(Span span, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size not equal to {size}, had a size of {span.Length.ToAssertString()}"); } @@ -55,7 +55,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(Span span, i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(Span span, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThan(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}"); } @@ -65,7 +65,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan(Span span, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Span span, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}"); } @@ -75,7 +75,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Span< /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(Span span, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThan(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size less than {size}, had a size of {span.Length.ToAssertString()}"); } @@ -85,7 +85,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(Span span, int /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span span, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size less than or equal to {size}, had a size of {span.Length.ToAssertString()}"); } @@ -95,7 +95,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(Span source, Span destination, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(Span source, Span destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); } @@ -105,7 +105,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(Span source, Sp /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span source, Span destination, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span source, Span destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); } @@ -115,7 +115,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Span span, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Span span, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {span.Length.ToAssertString()} to be a valid index for the target collection ({typeof(Span).ToTypeString()}), was {index.ToAssertString()}"); } @@ -125,7 +125,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Span span, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Span span, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {span.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(Span).ToTypeString()}), was {index.ToAssertString()}"); } @@ -135,7 +135,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int ind /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(ReadOnlySpan span, string name) + internal static void ThrowArgumentExceptionForIsEmpty(ReadOnlySpan span, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must be empty, had a size of {span.Length.ToAssertString()}"); } @@ -145,7 +145,7 @@ public static void ThrowArgumentExceptionForIsEmpty(ReadOnlySpan span, str /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan span, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size equal to {size}, had a size of {span.Length.ToAssertString()}"); } @@ -155,7 +155,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan sp /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlySpan span, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size not equal to {size}, had a size of {span.Length.ToAssertString()}"); } @@ -165,7 +165,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlySpan /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlySpan span, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}"); } @@ -175,7 +175,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlySpan [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlySpan span, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}"); } @@ -185,7 +185,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadO /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlySpan span, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than {size}, had a size of {span.Length.ToAssertString()}"); } @@ -195,7 +195,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlySpan s /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlySpan span, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than or equal to {size}, had a size of {span.Length.ToAssertString()}"); } @@ -205,7 +205,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnly /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan source, Span destination, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan source, Span destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); } @@ -215,7 +215,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan so /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlySpan source, Span destination, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlySpan source, Span destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); } @@ -225,7 +225,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnly /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlySpan span, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlySpan span, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {span.Length.ToAssertString()} to be a valid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {index.ToAssertString()}"); } @@ -235,7 +235,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlySpan span, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlySpan span, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {span.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {index.ToAssertString()}"); } @@ -245,7 +245,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int ind /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(Memory memory, string name) + internal static void ThrowArgumentExceptionForIsEmpty(Memory memory, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must be empty, had a size of {memory.Length.ToAssertString()}"); } @@ -255,7 +255,7 @@ public static void ThrowArgumentExceptionForIsEmpty(Memory memory, string /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(Memory memory, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size equal to {size}, had a size of {memory.Length.ToAssertString()}"); } @@ -265,7 +265,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(Memory memory, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(Memory memory, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size not equal to {size}, had a size of {memory.Length.ToAssertString()}"); } @@ -275,7 +275,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(Memory memor /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(Memory memory, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThan(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}"); } @@ -285,7 +285,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan(Memory memo /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Memory memory, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}"); } @@ -295,7 +295,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Memor /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(Memory memory, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThan(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size less than {size}, had a size of {memory.Length.ToAssertString()}"); } @@ -305,7 +305,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(Memory memory, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory memory, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size less than or equal to {size}, had a size of {memory.Length.ToAssertString()}"); } @@ -315,7 +315,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(Memory source, Memory destination, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(Memory source, Memory destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); } @@ -325,7 +325,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(Memory source, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory source, Memory destination, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory source, Memory destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); } @@ -335,7 +335,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Memory memory, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Memory memory, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {memory.Length.ToAssertString()} to be a valid index for the target collection ({typeof(Memory).ToTypeString()}), was {index.ToAssertString()}"); } @@ -345,7 +345,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Memory memory, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Memory memory, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {memory.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(Memory).ToTypeString()}), was {index.ToAssertString()}"); } @@ -355,7 +355,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int ind /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(ReadOnlyMemory memory, string name) + internal static void ThrowArgumentExceptionForIsEmpty(ReadOnlyMemory memory, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must be empty, had a size of {memory.Length.ToAssertString()}"); } @@ -365,7 +365,7 @@ public static void ThrowArgumentExceptionForIsEmpty(ReadOnlyMemory memory, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory memory, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size equal to {size}, had a size of {memory.Length.ToAssertString()}"); } @@ -375,7 +375,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlyMemory memory, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size not equal to {size}, had a size of {memory.Length.ToAssertString()}"); } @@ -385,7 +385,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlyMemory< /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlyMemory memory, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}"); } @@ -395,7 +395,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlyMemory /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlyMemory memory, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}"); } @@ -405,7 +405,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadO /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlyMemory memory, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than {size}, had a size of {memory.Length.ToAssertString()}"); } @@ -415,7 +415,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlyMemory /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlyMemory memory, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than or equal to {size}, had a size of {memory.Length.ToAssertString()}"); } @@ -425,7 +425,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnly /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory source, Memory destination, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory source, Memory destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); } @@ -435,7 +435,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlyMemory source, Memory destination, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlyMemory source, Memory destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); } @@ -445,7 +445,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnly /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlyMemory memory, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlyMemory memory, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {memory.Length.ToAssertString()} to be a valid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {index.ToAssertString()}"); } @@ -455,7 +455,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlyMemory memory, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlyMemory memory, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {memory.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {index.ToAssertString()}"); } @@ -465,7 +465,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int ind /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(T[] array, string name) + internal static void ThrowArgumentExceptionForIsEmpty(T[] array, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must be empty, had a size of {array.Length.ToAssertString()}"); } @@ -475,7 +475,7 @@ public static void ThrowArgumentExceptionForIsEmpty(T[] array, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(T[] array, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size equal to {size}, had a size of {array.Length.ToAssertString()}"); } @@ -485,7 +485,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(T[] array, int siz /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(T[] array, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size not equal to {size}, had a size of {array.Length.ToAssertString()}"); } @@ -495,7 +495,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(T[] array, int /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(T[] array, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThan(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size over {size}, had a size of {array.Length.ToAssertString()}"); } @@ -505,7 +505,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan(T[] array, int /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(T[] array, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size of at least {size}, had a size of {array.Length.ToAssertString()}"); } @@ -515,7 +515,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(T[] a /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(T[] array, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThan(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size less than {size}, had a size of {array.Length.ToAssertString()}"); } @@ -525,7 +525,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(T[] array, int si /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] array, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size less than or equal to {size}, had a size of {array.Length.ToAssertString()}"); } @@ -535,7 +535,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] arra /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(T[] source, T[] destination, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(T[] source, T[] destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); } @@ -545,7 +545,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(T[] source, T[] de /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] source, T[] destination, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] source, T[] destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); } @@ -555,7 +555,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] sour /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, T[] array, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, T[] array, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {array.Length.ToAssertString()} to be a valid index for the target collection ({typeof(T[]).ToTypeString()}), was {index.ToAssertString()}"); } @@ -565,7 +565,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, T[] array, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, T[] array, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {array.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(T[]).ToTypeString()}), was {index.ToAssertString()}"); } @@ -575,7 +575,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int ind /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(List list, string name) + internal static void ThrowArgumentExceptionForIsEmpty(List list, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must be empty, had a size of {list.Count.ToAssertString()}"); } @@ -585,7 +585,7 @@ public static void ThrowArgumentExceptionForIsEmpty(List list, string name /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(List list, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size equal to {size}, had a size of {list.Count.ToAssertString()}"); } @@ -595,7 +595,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(List list, int /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(List list, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size not equal to {size}, had a size of {list.Count.ToAssertString()}"); } @@ -605,7 +605,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(List list, i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(List list, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThan(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size over {size}, had a size of {list.Count.ToAssertString()}"); } @@ -615,7 +615,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan(List list, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(List list, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size of at least {size}, had a size of {list.Count.ToAssertString()}"); } @@ -625,7 +625,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(List< /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(List list, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThan(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size less than {size}, had a size of {list.Count.ToAssertString()}"); } @@ -635,7 +635,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(List list, int /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List list, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size less than or equal to {size}, had a size of {list.Count.ToAssertString()}"); } @@ -645,7 +645,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(List source, List destination, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(List source, List destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); } @@ -655,7 +655,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(List source, Li /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List source, List destination, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List source, List destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size less than or equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); } @@ -665,7 +665,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, List list, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, List list, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {list.Count.ToAssertString()} to be a valid index for the target collection ({typeof(List).ToTypeString()}), was {index.ToAssertString()}"); } @@ -675,7 +675,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, List list, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, List list, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {list.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(List).ToTypeString()}), was {index.ToAssertString()}"); } @@ -685,7 +685,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int ind /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(ICollection collection, string name) + internal static void ThrowArgumentExceptionForIsEmpty(ICollection collection, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must be empty, had a size of {collection.Count.ToAssertString()}"); } @@ -695,7 +695,7 @@ public static void ThrowArgumentExceptionForIsEmpty(ICollection collection /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection collection, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size equal to {size}, had a size of {collection.Count.ToAssertString()}"); } @@ -705,7 +705,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection col /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ICollection collection, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size not equal to {size}, had a size of {collection.Count.ToAssertString()}"); } @@ -715,7 +715,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ICollection /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(ICollection collection, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}"); } @@ -725,7 +725,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan(ICollection /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ICollection collection, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}"); } @@ -735,7 +735,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(IColl /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(ICollection collection, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThan(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size less than {size}, had a size of {collection.Count.ToAssertString()}"); } @@ -745,7 +745,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(ICollection co /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollection collection, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size less than or equal to {size}, had a size of {collection.Count.ToAssertString()}"); } @@ -755,7 +755,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollect /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection source, ICollection destination, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection source, ICollection destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); } @@ -765,7 +765,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection sou /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollection source, ICollection destination, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollection source, ICollection destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size less than or equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); } @@ -775,7 +775,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollect /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ICollection collection, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ICollection collection, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {collection.Count.ToAssertString()} to be a valid index for the target collection ({typeof(ICollection).ToTypeString()}), was {index.ToAssertString()}"); } @@ -785,7 +785,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ICollection collection, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ICollection collection, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {collection.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(ICollection).ToTypeString()}), was {index.ToAssertString()}"); } @@ -795,7 +795,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int ind /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(IReadOnlyCollection collection, string name) + internal static void ThrowArgumentExceptionForIsEmpty(IReadOnlyCollection collection, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must be empty, had a size of {collection.Count.ToAssertString()}"); } @@ -805,7 +805,7 @@ public static void ThrowArgumentExceptionForIsEmpty(IReadOnlyCollection co /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollection collection, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size equal to {size}, had a size of {collection.Count.ToAssertString()}"); } @@ -815,7 +815,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollectio /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(IReadOnlyCollection collection, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size not equal to {size}, had a size of {collection.Count.ToAssertString()}"); } @@ -825,7 +825,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(IReadOnlyCollec /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(IReadOnlyCollection collection, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThan(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}"); } @@ -835,7 +835,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan(IReadOnlyColle /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(IReadOnlyCollection collection, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}"); } @@ -845,7 +845,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(IRead /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(IReadOnlyCollection collection, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThan(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than {size}, had a size of {collection.Count.ToAssertString()}"); } @@ -855,7 +855,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(IReadOnlyCollecti /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnlyCollection collection, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than or equal to {size}, had a size of {collection.Count.ToAssertString()}"); } @@ -865,7 +865,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnl /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollection source, ICollection destination, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollection source, ICollection destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); } @@ -875,7 +875,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollectio /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnlyCollection source, ICollection destination, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnlyCollection source, ICollection destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than or equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); } @@ -885,7 +885,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnl /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, IReadOnlyCollection collection, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, IReadOnlyCollection collection, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {collection.Count.ToAssertString()} to be a valid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {index.ToAssertString()}"); } @@ -895,7 +895,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, IReadOnlyCollection collection, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, IReadOnlyCollection collection, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {collection.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {index.ToAssertString()}"); } diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt index 98d72977851..2c64db2769d 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt @@ -15,7 +15,7 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { <# GenerateTextForItems(EnumerableTypes, item => @@ -26,7 +26,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(<#=item.Type#> <#=item.Name#>, string name) + internal static void ThrowArgumentExceptionForIsEmpty(<#=item.Type#> <#=item.Name#>, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must be empty, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); } @@ -36,7 +36,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); } @@ -46,7 +46,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size not equal to {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); } @@ -56,7 +56,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(<#=item.Type#> <#=item.Name#>, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThan(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size over {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); } @@ -66,7 +66,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size of at least {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); } @@ -76,7 +76,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(<#=item.Type#> <#=item.Name#>, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThan(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); } @@ -86,7 +86,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); } @@ -96,7 +96,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {destination.<#=item.Size#>.ToAssertString()} (the destination), had a size of {source.<#=item.Size#>.ToAssertString()}"); } @@ -106,7 +106,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {destination.<#=item.Size#>.ToAssertString()} (the destination), had a size of {source.<#=item.Size#>.ToAssertString()}"); } @@ -116,7 +116,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {<#=item.Name#>.<#=item.Size#>.ToAssertString()} to be a valid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {index.ToAssertString()}"); } @@ -126,7 +126,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {<#=item.Name#>.<#=item.Size#>.ToAssertString()} to be an invalid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {index.ToAssertString()}"); } diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs index db4b4037756..64553be2387 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs @@ -14,7 +14,7 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { /// /// Throws an when fails. @@ -23,7 +23,7 @@ internal static partial class ThrowHelper /// This method is needed because can't be used as a generic type parameter. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) + internal static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must not be empty"); } @@ -35,7 +35,7 @@ public static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) /// This method is needed because can't be used as a generic type parameter. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(string name) + internal static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must not be empty"); } @@ -46,7 +46,7 @@ public static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(string /// The item of items in the input collection. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotEmpty(string name) + internal static void ThrowArgumentExceptionForIsNotEmpty(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be empty"); } diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs index b2dd7d2e4c6..ecf172241e4 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs @@ -14,7 +14,7 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { /// /// Throws an when fails. @@ -22,7 +22,7 @@ internal static partial class ThrowHelper /// The type of value type being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsDefault(T value, string name) + internal static void ThrowArgumentExceptionForIsDefault(T value, string name) where T : struct { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be the default value {default(T).ToAssertString()}, was {value.ToAssertString()}"); @@ -34,7 +34,7 @@ public static void ThrowArgumentExceptionForIsDefault(T value, string name) /// The type of value type being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotDefault(string name) + internal static void ThrowArgumentExceptionForIsNotDefault(string name) where T : struct { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be the default value {default(T).ToAssertString()}"); @@ -46,7 +46,7 @@ public static void ThrowArgumentExceptionForIsNotDefault(string name) /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEqualTo(T value, T target, string name) + internal static void ThrowArgumentExceptionForIsEqualTo(T value, T target, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be equal to {target.ToAssertString()}, was {value.ToAssertString()}"); } @@ -57,7 +57,7 @@ public static void ThrowArgumentExceptionForIsEqualTo(T value, T target, stri /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, string name) + internal static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be equal to {target.ToAssertString()}, was {value.ToAssertString()}"); } @@ -68,7 +68,7 @@ public static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, s /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T maximum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T maximum, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than {maximum.ToAssertString()}, was {value.ToAssertString()}"); } @@ -79,7 +79,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T m /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T value, T maximum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T value, T maximum, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than or equal to {maximum.ToAssertString()}, was {value.ToAssertString()}"); } @@ -90,7 +90,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T v /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value, T minimum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value, T minimum, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than {minimum.ToAssertString()}, was {value.ToAssertString()}"); } @@ -101,7 +101,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value, /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(T value, T minimum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(T value, T minimum, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than or equal to {minimum.ToAssertString()}, was {value.ToAssertString()}"); } @@ -112,7 +112,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo( /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T minimum, T maximum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } @@ -123,7 +123,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T mi /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, T minimum, T maximum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } @@ -134,7 +134,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, T /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T minimum, T maximum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } @@ -145,7 +145,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T mi /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, T minimum, T maximum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } @@ -156,7 +156,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, T /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T value, T minimum, T maximum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } @@ -167,7 +167,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T va /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo(T value, T minimum, T maximum, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs index d3a2171f6a1..fef5019e6e6 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs @@ -14,14 +14,14 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { /// /// Throws an when fails. /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsCloseTo(int value, int target, uint delta, string name) + internal static void ThrowArgumentExceptionForIsCloseTo(int value, int target, uint delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(int).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((double)((long)value - target)).ToAssertString()}"); } @@ -31,7 +31,7 @@ public static void ThrowArgumentExceptionForIsCloseTo(int value, int target, uin /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotCloseTo(int value, int target, uint delta, string name) + internal static void ThrowArgumentExceptionForIsNotCloseTo(int value, int target, uint delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(int).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((double)((long)value - target)).ToAssertString()}"); } @@ -41,7 +41,7 @@ public static void ThrowArgumentExceptionForIsNotCloseTo(int value, int target, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsCloseTo(long value, long target, ulong delta, string name) + internal static void ThrowArgumentExceptionForIsCloseTo(long value, long target, ulong delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(long).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((decimal)value - target).ToAssertString()}"); } @@ -51,7 +51,7 @@ public static void ThrowArgumentExceptionForIsCloseTo(long value, long target, u /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotCloseTo(long value, long target, ulong delta, string name) + internal static void ThrowArgumentExceptionForIsNotCloseTo(long value, long target, ulong delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(long).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((decimal)value - target).ToAssertString()}"); } @@ -61,7 +61,7 @@ public static void ThrowArgumentExceptionForIsNotCloseTo(long value, long target /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsCloseTo(float value, float target, float delta, string name) + internal static void ThrowArgumentExceptionForIsCloseTo(float value, float target, float delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(float).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); } @@ -71,7 +71,7 @@ public static void ThrowArgumentExceptionForIsCloseTo(float value, float target, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotCloseTo(float value, float target, float delta, string name) + internal static void ThrowArgumentExceptionForIsNotCloseTo(float value, float target, float delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(float).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); } @@ -81,7 +81,7 @@ public static void ThrowArgumentExceptionForIsNotCloseTo(float value, float targ /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsCloseTo(double value, double target, double delta, string name) + internal static void ThrowArgumentExceptionForIsCloseTo(double value, double target, double delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(double).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); } @@ -91,7 +91,7 @@ public static void ThrowArgumentExceptionForIsCloseTo(double value, double targe /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotCloseTo(double value, double target, double delta, string name) + internal static void ThrowArgumentExceptionForIsNotCloseTo(double value, double target, double delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(double).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); } diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs index a4f750b9b3e..b8cfebe6b6e 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs @@ -15,14 +15,14 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { /// /// Throws an when fails. /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForCanRead(Stream stream, string name) + internal static void ThrowArgumentExceptionForCanRead(Stream stream, string name) { ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support reading"); } @@ -32,7 +32,7 @@ public static void ThrowArgumentExceptionForCanRead(Stream stream, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForCanWrite(Stream stream, string name) + internal static void ThrowArgumentExceptionForCanWrite(Stream stream, string name) { ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support writing"); } @@ -42,7 +42,7 @@ public static void ThrowArgumentExceptionForCanWrite(Stream stream, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForCanSeek(Stream stream, string name) + internal static void ThrowArgumentExceptionForCanSeek(Stream stream, string name) { ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support seeking"); } @@ -52,7 +52,7 @@ public static void ThrowArgumentExceptionForCanSeek(Stream stream, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsAtStartPosition(Stream stream, string name) + internal static void ThrowArgumentExceptionForIsAtStartPosition(Stream stream, string name) { ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) must be at position {0.ToAssertString()}, was at {stream.Position.ToAssertString()}"); } diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs index d986ebb67dd..cccc21f6421 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs @@ -13,14 +13,14 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { /// /// Throws an when fails. /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNullOrEmpty(string? text, string name) + internal static void ThrowArgumentExceptionForIsNullOrEmpty(string? text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be null or empty, was {text.ToAssertString()}"); } @@ -30,7 +30,7 @@ public static void ThrowArgumentExceptionForIsNullOrEmpty(string? text, string n /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotNullOrEmpty(string? text, string name) + internal static void ThrowArgumentExceptionForIsNotNullOrEmpty(string? text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be null or empty, was {(text is null ? "null" : "empty")}"); } @@ -40,7 +40,7 @@ public static void ThrowArgumentExceptionForIsNotNullOrEmpty(string? text, strin /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNullOrWhitespace(string? text, string name) + internal static void ThrowArgumentExceptionForIsNullOrWhitespace(string? text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be null or whitespace, was {text.ToAssertString()}"); } @@ -50,7 +50,7 @@ public static void ThrowArgumentExceptionForIsNullOrWhitespace(string? text, str /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotNullOrWhitespace(string? text, string name) + internal static void ThrowArgumentExceptionForIsNotNullOrWhitespace(string? text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be null or whitespace, was {(text is null ? "null" : "whitespace")}"); } @@ -60,7 +60,7 @@ public static void ThrowArgumentExceptionForIsNotNullOrWhitespace(string? text, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsEmpty(string text, string name) + internal static void ThrowArgumentExceptionForIsEmpty(string text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be empty, was {text.ToAssertString()}"); } @@ -70,7 +70,7 @@ public static void ThrowArgumentExceptionForIsEmpty(string text, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotEmpty(string text, string name) + internal static void ThrowArgumentExceptionForIsNotEmpty(string text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be empty"); } @@ -80,7 +80,7 @@ public static void ThrowArgumentExceptionForIsNotEmpty(string text, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsWhitespace(string text, string name) + internal static void ThrowArgumentExceptionForIsWhitespace(string text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be whitespace, was {text.ToAssertString()}"); } @@ -90,7 +90,7 @@ public static void ThrowArgumentExceptionForIsWhitespace(string text, string nam /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotWhitespace(string text, string name) + internal static void ThrowArgumentExceptionForIsNotWhitespace(string text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be whitespace, was {text.ToAssertString()}"); } @@ -100,7 +100,7 @@ public static void ThrowArgumentExceptionForIsNotWhitespace(string text, string /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size equal to {size}, had a size of {text.Length} and was {text.ToAssertString()}"); } @@ -110,7 +110,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int size /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeNotEqualTo(string text, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not have a size equal to {size}, was {text.ToAssertString()}"); } @@ -120,7 +120,7 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(string text, int s /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThan(string text, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThan(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size over {size}, had a size of {text.Length} and was {text.ToAssertString()}"); } @@ -130,7 +130,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThan(string text, int /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(string text, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size of at least {size}, had a size of {text.Length} and was {text.ToAssertString()}"); } @@ -140,7 +140,7 @@ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(string t /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThan(string text, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThan(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size less than {size}, had a size of {text.Length} and was {text.ToAssertString()}"); } @@ -150,7 +150,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(string text, int siz /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string text, int size, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size less than or equal to {size}, had a size of {text.Length} and was {text.ToAssertString()}"); } @@ -160,7 +160,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string text /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeEqualTo(string source, string destination, string name) + internal static void ThrowArgumentExceptionForHasSizeEqualTo(string source, string destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} (string) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); } @@ -170,7 +170,7 @@ public static void ThrowArgumentExceptionForHasSizeEqualTo(string source, string /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string source, string destination, string name) + internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string source, string destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} (string) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); } @@ -180,7 +180,7 @@ public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string sour /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, string text, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, string text, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {text.Length.ToAssertString()} to be a valid index for the target string, was {index.ToAssertString()}"); } @@ -190,7 +190,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, st /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, string text, string name) + internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, string text, string name) { ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {text.Length.ToAssertString()} to be an invalid index for the target string, was {index.ToAssertString()}"); } diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs index f25af5139d6..2689a32cec2 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs @@ -15,14 +15,14 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { /// /// Throws an when fails. /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsCompleted(Task task, string name) + internal static void ThrowArgumentExceptionForIsCompleted(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be completed, had status {task.Status.ToAssertString()}"); } @@ -32,7 +32,7 @@ public static void ThrowArgumentExceptionForIsCompleted(Task task, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotCompleted(Task task, string name) + internal static void ThrowArgumentExceptionForIsNotCompleted(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be completed, had status {task.Status.ToAssertString()}"); } @@ -42,7 +42,7 @@ public static void ThrowArgumentExceptionForIsNotCompleted(Task task, string nam /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsCompletedSuccessfully(Task task, string name) + internal static void ThrowArgumentExceptionForIsCompletedSuccessfully(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be completed successfully, had status {task.Status.ToAssertString()}"); } @@ -52,7 +52,7 @@ public static void ThrowArgumentExceptionForIsCompletedSuccessfully(Task task, s /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotCompletedSuccessfully(Task task, string name) + internal static void ThrowArgumentExceptionForIsNotCompletedSuccessfully(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be completed successfully, had status {task.Status.ToAssertString()}"); } @@ -62,7 +62,7 @@ public static void ThrowArgumentExceptionForIsNotCompletedSuccessfully(Task task /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsFaulted(Task task, string name) + internal static void ThrowArgumentExceptionForIsFaulted(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be faulted, had status {task.Status.ToAssertString()}"); } @@ -72,7 +72,7 @@ public static void ThrowArgumentExceptionForIsFaulted(Task task, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotFaulted(Task task, string name) + internal static void ThrowArgumentExceptionForIsNotFaulted(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be faulted, had status {task.Status.ToAssertString()}"); } @@ -82,7 +82,7 @@ public static void ThrowArgumentExceptionForIsNotFaulted(Task task, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsCanceled(Task task, string name) + internal static void ThrowArgumentExceptionForIsCanceled(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be canceled, had status {task.Status.ToAssertString()}"); } @@ -92,7 +92,7 @@ public static void ThrowArgumentExceptionForIsCanceled(Task task, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotCanceled(Task task, string name) + internal static void ThrowArgumentExceptionForIsNotCanceled(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be canceled, had status {task.Status.ToAssertString()}"); } @@ -102,7 +102,7 @@ public static void ThrowArgumentExceptionForIsNotCanceled(Task task, string name /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasStatusEqualTo(Task task, TaskStatus status, string name) + internal static void ThrowArgumentExceptionForHasStatusEqualTo(Task task, TaskStatus status, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must have status {status}, had status {task.Status.ToAssertString()}"); } @@ -112,7 +112,7 @@ public static void ThrowArgumentExceptionForHasStatusEqualTo(Task task, TaskStat /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForHasStatusNotEqualTo(Task task, TaskStatus status, string name) + internal static void ThrowArgumentExceptionForHasStatusNotEqualTo(Task task, TaskStatus status, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not have status {status.ToAssertString()}"); } diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs index 705f10fad4a..d3c15e79ace 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs @@ -13,7 +13,7 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { /// /// Returns a formatted representation of the input value. @@ -38,7 +38,7 @@ private static string ToAssertString(this object? obj) /// The message to include in the exception. /// Thrown with and . [DoesNotReturn] - private static void ThrowArgumentException(string name, string message) + internal static void ThrowArgumentException(string name, string message) { throw new ArgumentException(message, name); } @@ -50,7 +50,7 @@ private static void ThrowArgumentException(string name, string message) /// The message to include in the exception. /// Thrown with and . [DoesNotReturn] - private static void ThrowArgumentNullException(string name, string message) + internal static void ThrowArgumentNullException(string name, string message) { throw new ArgumentNullException(name, message); } @@ -62,7 +62,7 @@ private static void ThrowArgumentNullException(string name, string message) /// The message to include in the exception. /// Thrown with and . [DoesNotReturn] - private static void ThrowArgumentOutOfRangeException(string name, string message) + internal static void ThrowArgumentOutOfRangeException(string name, string message) { throw new ArgumentOutOfRangeException(name, message); } diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs index aad8c57b9f0..d95e2320274 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs @@ -14,7 +14,7 @@ namespace Microsoft.Toolkit.Diagnostics /// /// Helper methods to throw exceptions /// - internal static partial class ThrowHelper + public static partial class ThrowHelper { /// /// Throws an when (where is ) fails. @@ -22,7 +22,7 @@ internal static partial class ThrowHelper /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNull(T value, string name) + internal static void ThrowArgumentExceptionForIsNull(T value, string name) where T : class { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be null, was {value.ToAssertString()} ({value.GetType().ToTypeString()})"); @@ -34,7 +34,7 @@ public static void ThrowArgumentExceptionForIsNull(T value, string name) /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNull(T? value, string name) + internal static void ThrowArgumentExceptionForIsNull(T? value, string name) where T : struct { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T?).ToTypeString()}) must be null, was {value.ToAssertString()} ({typeof(T).ToTypeString()})"); @@ -46,7 +46,7 @@ public static void ThrowArgumentExceptionForIsNull(T? value, string name) /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentNullExceptionForIsNotNull(string name) + internal static void ThrowArgumentNullExceptionForIsNotNull(string name) { ThrowArgumentNullException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be not null)"); } @@ -57,7 +57,7 @@ public static void ThrowArgumentNullExceptionForIsNotNull(string name) /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsOfType(object value, string name) + internal static void ThrowArgumentExceptionForIsOfType(object value, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); } @@ -68,7 +68,7 @@ public static void ThrowArgumentExceptionForIsOfType(object value, string nam /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotOfType(object value, string name) + internal static void ThrowArgumentExceptionForIsNotOfType(object value, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); } @@ -78,7 +78,7 @@ public static void ThrowArgumentExceptionForIsNotOfType(object value, string /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsOfType(object value, Type type, string name) + internal static void ThrowArgumentExceptionForIsOfType(object value, Type type, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); } @@ -88,7 +88,7 @@ public static void ThrowArgumentExceptionForIsOfType(object value, Type type, st /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotOfType(object value, Type type, string name) + internal static void ThrowArgumentExceptionForIsNotOfType(object value, Type type, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); } @@ -99,7 +99,7 @@ public static void ThrowArgumentExceptionForIsNotOfType(object value, Type type, /// The type being checked against. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsAssignableToType(object value, string name) + internal static void ThrowArgumentExceptionForIsAssignableToType(object value, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); } @@ -110,7 +110,7 @@ public static void ThrowArgumentExceptionForIsAssignableToType(object value, /// The type being checked against. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotAssignableToType(object value, string name) + internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); } @@ -120,7 +120,7 @@ public static void ThrowArgumentExceptionForIsNotAssignableToType(object valu /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsAssignableToType(object value, Type type, string name) + internal static void ThrowArgumentExceptionForIsAssignableToType(object value, Type type, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); } @@ -130,7 +130,7 @@ public static void ThrowArgumentExceptionForIsAssignableToType(object value, Typ /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsNotAssignableToType(object value, Type type, string name) + internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value, Type type, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); } @@ -141,7 +141,7 @@ public static void ThrowArgumentExceptionForIsNotAssignableToType(object value, /// The type of input values being compared. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForsBitwiseEqualTo(T value, T target, string name) + internal static void ThrowArgumentExceptionForsBitwiseEqualTo(T value, T target, string name) where T : unmanaged { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) is not a bitwise match, was <{value.ToHexString()}> instead of <{target.ToHexString()}>"); @@ -153,7 +153,7 @@ public static void ThrowArgumentExceptionForsBitwiseEqualTo(T value, T target /// The type of input value being compared. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsReferenceEqualTo(string name) + internal static void ThrowArgumentExceptionForIsReferenceEqualTo(string name) where T : class { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be the same instance as the target object"); @@ -165,7 +165,7 @@ public static void ThrowArgumentExceptionForIsReferenceEqualTo(string name) /// The type of input value being compared. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsReferenceNotEqualTo(string name) + internal static void ThrowArgumentExceptionForIsReferenceNotEqualTo(string name) where T : class { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be the same instance as the target object"); @@ -176,7 +176,7 @@ public static void ThrowArgumentExceptionForIsReferenceNotEqualTo(string name /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsTrue(string name) + internal static void ThrowArgumentExceptionForIsTrue(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false"); } @@ -186,7 +186,7 @@ public static void ThrowArgumentExceptionForIsTrue(string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsTrue(string name, string message) + internal static void ThrowArgumentExceptionForIsTrue(string name, string message) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false: {message.ToAssertString()}"); } @@ -196,7 +196,7 @@ public static void ThrowArgumentExceptionForIsTrue(string name, string message) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsFalse(string name) + internal static void ThrowArgumentExceptionForIsFalse(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true"); } @@ -206,7 +206,7 @@ public static void ThrowArgumentExceptionForIsFalse(string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - public static void ThrowArgumentExceptionForIsFalse(string name, string message) + internal static void ThrowArgumentExceptionForIsFalse(string name, string message) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true: {message.ToAssertString()}"); } From a90acfc8f80b7f163df6f45a01445a5fe301051b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 14 Jun 2020 20:54:51 +0200 Subject: [PATCH 03/19] Improved construction of ArgumentOutOfRangeException-s --- .../Generated/ThrowHelper.Collection.g.cs | 32 +++++++++---------- .../Generated/ThrowHelper.Collection.tt | 4 +-- .../ThrowHelper.Comparable.Generic.cs | 20 ++++++------ .../Diagnostics/ThrowHelper.String.cs | 4 +-- .../ThrowHelper.ThrowExceptions.cs | 5 +-- 5 files changed, 33 insertions(+), 32 deletions(-) diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs index d104090bb41..8c9026be221 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs @@ -117,7 +117,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span(int index, Span span, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {span.Length.ToAssertString()} to be a valid index for the target collection ({typeof(Span).ToTypeString()}), was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {span.Length.ToAssertString()} to be a valid index for the target collection ({typeof(Span).ToTypeString()}), was {index.ToAssertString()}"); } /// @@ -127,7 +127,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Span span, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {span.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(Span).ToTypeString()}), was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {span.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(Span).ToTypeString()}), was {index.ToAssertString()}"); } /// @@ -227,7 +227,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOn [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlySpan span, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {span.Length.ToAssertString()} to be a valid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {span.Length.ToAssertString()} to be a valid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {index.ToAssertString()}"); } /// @@ -237,7 +237,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlySpan span, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {span.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {span.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {index.ToAssertString()}"); } /// @@ -337,7 +337,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Memory memory, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {memory.Length.ToAssertString()} to be a valid index for the target collection ({typeof(Memory).ToTypeString()}), was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {memory.Length.ToAssertString()} to be a valid index for the target collection ({typeof(Memory).ToTypeString()}), was {index.ToAssertString()}"); } /// @@ -347,7 +347,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Memory memory, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {memory.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(Memory).ToTypeString()}), was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {memory.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(Memory).ToTypeString()}), was {index.ToAssertString()}"); } /// @@ -447,7 +447,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOn [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlyMemory memory, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {memory.Length.ToAssertString()} to be a valid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {memory.Length.ToAssertString()} to be a valid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {index.ToAssertString()}"); } /// @@ -457,7 +457,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlyMemory memory, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {memory.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {memory.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {index.ToAssertString()}"); } /// @@ -557,7 +557,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] so [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, T[] array, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {array.Length.ToAssertString()} to be a valid index for the target collection ({typeof(T[]).ToTypeString()}), was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {array.Length.ToAssertString()} to be a valid index for the target collection ({typeof(T[]).ToTypeString()}), was {index.ToAssertString()}"); } /// @@ -567,7 +567,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, T[] array, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {array.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(T[]).ToTypeString()}), was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {array.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(T[]).ToTypeString()}), was {index.ToAssertString()}"); } /// @@ -667,7 +667,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List(int index, List list, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {list.Count.ToAssertString()} to be a valid index for the target collection ({typeof(List).ToTypeString()}), was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {list.Count.ToAssertString()} to be a valid index for the target collection ({typeof(List).ToTypeString()}), was {index.ToAssertString()}"); } /// @@ -677,7 +677,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, List list, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {list.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(List).ToTypeString()}), was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {list.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(List).ToTypeString()}), was {index.ToAssertString()}"); } /// @@ -777,7 +777,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IColle [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ICollection collection, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {collection.Count.ToAssertString()} to be a valid index for the target collection ({typeof(ICollection).ToTypeString()}), was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {collection.Count.ToAssertString()} to be a valid index for the target collection ({typeof(ICollection).ToTypeString()}), was {index.ToAssertString()}"); } /// @@ -787,7 +787,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ICollection collection, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {collection.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(ICollection).ToTypeString()}), was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {collection.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(ICollection).ToTypeString()}), was {index.ToAssertString()}"); } /// @@ -887,7 +887,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadO [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, IReadOnlyCollection collection, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {collection.Count.ToAssertString()} to be a valid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {collection.Count.ToAssertString()} to be a valid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {index.ToAssertString()}"); } /// @@ -897,7 +897,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, IReadOnlyCollection collection, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {collection.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {collection.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {index.ToAssertString()}"); } } } diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt index 2c64db2769d..c52adafacda 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt @@ -118,7 +118,7 @@ GenerateTextForItems(EnumerableTypes, item => [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {<#=item.Name#>.<#=item.Size#>.ToAssertString()} to be a valid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {<#=item.Name#>.<#=item.Size#>.ToAssertString()} to be a valid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {index.ToAssertString()}"); } /// @@ -128,7 +128,7 @@ GenerateTextForItems(EnumerableTypes, item => [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {<#=item.Name#>.<#=item.Size#>.ToAssertString()} to be an invalid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {<#=item.Name#>.<#=item.Size#>.ToAssertString()} to be an invalid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {index.ToAssertString()}"); } <# }); diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs index ecf172241e4..aa45dc82702 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs @@ -70,7 +70,7 @@ internal static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than {maximum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// @@ -81,7 +81,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T value, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than or equal to {maximum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than or equal to {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// @@ -92,7 +92,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value, T minimum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than {minimum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than {minimum.ToAssertString()}, was {value.ToAssertString()}"); } /// @@ -103,7 +103,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(T value, T minimum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than or equal to {minimum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than or equal to {minimum.ToAssertString()}, was {value.ToAssertString()}"); } /// @@ -114,7 +114,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(T value, T minimum, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// @@ -125,7 +125,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, T minimum, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// @@ -136,7 +136,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T minimum, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// @@ -147,7 +147,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, T minimum, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// @@ -158,7 +158,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T value, T minimum, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } /// @@ -169,7 +169,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo(T value, T minimum, T maximum, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); } } } diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs index cccc21f6421..8de060c0b1e 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs @@ -182,7 +182,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string so [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, string text, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {text.Length.ToAssertString()} to be a valid index for the target string, was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {text.Length.ToAssertString()} to be a valid index for the target string, was {index.ToAssertString()}"); } /// @@ -192,7 +192,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, [DoesNotReturn] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, string text, string name) { - ThrowArgumentOutOfRangeException(name, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {text.Length.ToAssertString()} to be an invalid index for the target string, was {index.ToAssertString()}"); + ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {text.Length.ToAssertString()} to be an invalid index for the target string, was {index.ToAssertString()}"); } } } diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs index d3c15e79ace..733cb1699a1 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs @@ -59,12 +59,13 @@ internal static void ThrowArgumentNullException(string name, string message) /// Throws a new . /// /// The argument name. + /// The current argument value. /// The message to include in the exception. /// Thrown with and . [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeException(string name, string message) + internal static void ThrowArgumentOutOfRangeException(string name, object value, string message) { - throw new ArgumentOutOfRangeException(name, message); + throw new ArgumentOutOfRangeException(name, value, message); } } } From b63b34b8f73605cf956c9cec5a5f631122f3b64f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 14 Jun 2020 21:54:05 +0200 Subject: [PATCH 04/19] Made current thrower public, minor API additions --- .../ThrowHelper.ThrowExceptions.cs | 64 +++++++++++++++++-- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs index 733cb1699a1..f252704e67b 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs @@ -31,6 +31,28 @@ private static string ToAssertString(this object? obj) }; } + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with . + [DoesNotReturn] + public static void ThrowAccessViolationException(string message) + { + throw new AccessViolationException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with . + [DoesNotReturn] + public static void ThrowArgumentException(string message) + { + throw new ArgumentException(message); + } + /// /// Throws a new . /// @@ -38,11 +60,22 @@ private static string ToAssertString(this object? obj) /// The message to include in the exception. /// Thrown with and . [DoesNotReturn] - internal static void ThrowArgumentException(string name, string message) + public static void ThrowArgumentException(string name, string message) { throw new ArgumentException(message, name); } + /// + /// Throws a new . + /// + /// The argument name. + /// Thrown with . + [DoesNotReturn] + public static void ThrowArgumentNullException(string name) + { + throw new ArgumentNullException(name); + } + /// /// Throws a new . /// @@ -50,7 +83,7 @@ internal static void ThrowArgumentException(string name, string message) /// The message to include in the exception. /// Thrown with and . [DoesNotReturn] - internal static void ThrowArgumentNullException(string name, string message) + public static void ThrowArgumentNullException(string name, string message) { throw new ArgumentNullException(name, message); } @@ -59,11 +92,34 @@ internal static void ThrowArgumentNullException(string name, string message) /// Throws a new . /// /// The argument name. - /// The current argument value. + /// Thrown with . + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeException(string name) + { + throw new ArgumentOutOfRangeException(name); + } + + /// + /// Throws a new . + /// + /// The argument name. /// The message to include in the exception. /// Thrown with and . [DoesNotReturn] - internal static void ThrowArgumentOutOfRangeException(string name, object value, string message) + public static void ThrowArgumentOutOfRangeException(string name, string message) + { + throw new ArgumentOutOfRangeException(name, message); + } + + /// + /// Throws a new . + /// + /// The argument name. + /// The current argument value. + /// The message to include in the exception. + /// Thrown with , and . + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeException(string name, object value, string message) { throw new ArgumentOutOfRangeException(name, value, message); } From 33b83ab677eb114fe11880dc09dd7598fb9fc965 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 14 Jun 2020 22:07:28 +0200 Subject: [PATCH 05/19] Added more throw helper APIs --- .../ThrowHelper.ThrowExceptions.cs | 269 ++++++++++++++++-- 1 file changed, 253 insertions(+), 16 deletions(-) diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs index f252704e67b..d0dd0a3ed75 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs @@ -5,6 +5,7 @@ using System; using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; +using System.Threading; #nullable enable @@ -15,22 +16,6 @@ namespace Microsoft.Toolkit.Diagnostics /// public static partial class ThrowHelper { - /// - /// Returns a formatted representation of the input value. - /// - /// The input to format. - /// A formatted representation of to display in error messages. - [Pure] - private static string ToAssertString(this object? obj) - { - return obj switch - { - string _ => $"\"{obj}\"", - null => "null", - _ => $"<{obj}>" - }; - } - /// /// Throws a new . /// @@ -123,5 +108,257 @@ public static void ThrowArgumentOutOfRangeException(string name, object value, s { throw new ArgumentOutOfRangeException(name, value, message); } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with . + [DoesNotReturn] + public static void ThrowFormatException(string message) + { + throw new FormatException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with . + [DoesNotReturn] + public static void ThrowIndexOutOfRangeException(string message) + { + throw new IndexOutOfRangeException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with . + [DoesNotReturn] + public static void ThrowInsufficientMemoryException(string message) + { + throw new InsufficientMemoryException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with . + [DoesNotReturn] + public static void ThrowInvalidOperationException(string message) + { + throw new InvalidOperationException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with . + [DoesNotReturn] + public static void ThrowMissingFieldException(string message) + { + throw new MissingFieldException(message); + } + + /// + /// Throws a new . + /// + /// The target class being inspected. + /// The target field being retrieved. + /// Thrown with and . + [DoesNotReturn] + public static void ThrowMissingFieldException(string className, string fieldName) + { + throw new MissingFieldException(className, fieldName); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with . + [DoesNotReturn] + public static void ThrowMissingMemberException(string message) + { + throw new MissingMemberException(message); + } + + /// + /// Throws a new . + /// + /// The target class being inspected. + /// The target member being retrieved. + /// Thrown with and . + [DoesNotReturn] + public static void ThrowMissingMemberException(string className, string memberName) + { + throw new MissingMemberException(className, memberName); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with . + [DoesNotReturn] + public static void ThrowMissingMethodException(string message) + { + throw new MissingMethodException(message); + } + + /// + /// Throws a new . + /// + /// The target class being inspected. + /// The target method being retrieved. + /// Thrown with and . + [DoesNotReturn] + public static void ThrowMissingMethodException(string className, string methodName) + { + throw new MissingMethodException(className, methodName); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with . + [DoesNotReturn] + public static void ThrowNotSupportedException(string message) + { + throw new NotSupportedException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with . + [DoesNotReturn] + public static void ThrowNullReferenceException(string message) + { + throw new NullReferenceException(message); + } + + /// + /// Throws a new . + /// + /// The name of the disposed object. + /// Thrown with . + [DoesNotReturn] + public static void ThrowObjectDisposedException(string objectName) + { + throw new ObjectDisposedException(objectName); + } + + /// + /// Throws a new . + /// + /// The name of the disposed object. + /// The message to include in the exception. + /// Thrown with and . + [DoesNotReturn] + public static void ThrowObjectDisposedException(string objectName, string message) + { + throw new ObjectDisposedException(objectName, message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with . + [DoesNotReturn] + public static void ThrowOperationCanceledException(string message) + { + throw new OperationCanceledException(message); + } + + /// + /// Throws a new . + /// + /// The in use. + /// Thrown with . + [DoesNotReturn] + public static void ThrowOperationCanceledException(CancellationToken token) + { + throw new OperationCanceledException(token); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The in use. + /// Thrown with and . + [DoesNotReturn] + public static void ThrowThrowOperationCanceledException(string message, CancellationToken token) + { + throw new OperationCanceledException(message, token); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with . + [DoesNotReturn] + public static void ThrowOutOfMemoryException(string message) + { + throw new OutOfMemoryException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with . + [DoesNotReturn] + public static void ThrowPlatformNotSupportedException(string message) + { + throw new PlatformNotSupportedException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with . + [DoesNotReturn] + public static void ThrowTimeoutException(string message) + { + throw new TimeoutException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with . + [DoesNotReturn] + public static void ThrowUnauthorizedAccessException(string message) + { + throw new UnauthorizedAccessException(message); + } + + /// + /// Returns a formatted representation of the input value. + /// + /// The input to format. + /// A formatted representation of to display in error messages. + [Pure] + private static string ToAssertString(this object? obj) + { + return obj switch + { + string _ => $"\"{obj}\"", + null => "null", + _ => $"<{obj}>" + }; + } } } From 480b8609933e71cc363a0df58fbdcba1fb12d895 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 14 Jun 2020 22:19:01 +0200 Subject: [PATCH 06/19] Removed some throw helpers according to docs See https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/using-standard-exception-types --- .../ThrowHelper.ThrowExceptions.cs | 44 ------------------- 1 file changed, 44 deletions(-) diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs index d0dd0a3ed75..765f6f555a7 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs @@ -16,17 +16,6 @@ namespace Microsoft.Toolkit.Diagnostics /// public static partial class ThrowHelper { - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with . - [DoesNotReturn] - public static void ThrowAccessViolationException(string message) - { - throw new AccessViolationException(message); - } - /// /// Throws a new . /// @@ -120,17 +109,6 @@ public static void ThrowFormatException(string message) throw new FormatException(message); } - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with . - [DoesNotReturn] - public static void ThrowIndexOutOfRangeException(string message) - { - throw new IndexOutOfRangeException(message); - } - /// /// Throws a new . /// @@ -233,17 +211,6 @@ public static void ThrowNotSupportedException(string message) throw new NotSupportedException(message); } - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with . - [DoesNotReturn] - public static void ThrowNullReferenceException(string message) - { - throw new NullReferenceException(message); - } - /// /// Throws a new . /// @@ -301,17 +268,6 @@ public static void ThrowThrowOperationCanceledException(string message, Cancella throw new OperationCanceledException(message, token); } - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with . - [DoesNotReturn] - public static void ThrowOutOfMemoryException(string message) - { - throw new OutOfMemoryException(message); - } - /// /// Throws a new . /// From c9a9360625e594bb8b236a1424ffd785614c78b0 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 15 Jun 2020 02:29:21 +0200 Subject: [PATCH 07/19] Simplified XML docs --- .../ThrowHelper.ThrowExceptions.cs | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs index 765f6f555a7..5f2915dad6d 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs @@ -20,7 +20,7 @@ public static partial class ThrowHelper /// Throws a new . /// /// The message to include in the exception. - /// Thrown with . + /// Thrown with the specified parameter. [DoesNotReturn] public static void ThrowArgumentException(string message) { @@ -32,7 +32,7 @@ public static void ThrowArgumentException(string message) /// /// The argument name. /// The message to include in the exception. - /// Thrown with and . + /// Thrown with the specified parameters. [DoesNotReturn] public static void ThrowArgumentException(string name, string message) { @@ -43,7 +43,7 @@ public static void ThrowArgumentException(string name, string message) /// Throws a new . /// /// The argument name. - /// Thrown with . + /// Thrown with the specified parameter. [DoesNotReturn] public static void ThrowArgumentNullException(string name) { @@ -55,7 +55,7 @@ public static void ThrowArgumentNullException(string name) /// /// The argument name. /// The message to include in the exception. - /// Thrown with and . + /// Thrown with the specified parameters. [DoesNotReturn] public static void ThrowArgumentNullException(string name, string message) { @@ -66,7 +66,7 @@ public static void ThrowArgumentNullException(string name, string message) /// Throws a new . /// /// The argument name. - /// Thrown with . + /// Thrown with the specified parameter. [DoesNotReturn] public static void ThrowArgumentOutOfRangeException(string name) { @@ -78,7 +78,7 @@ public static void ThrowArgumentOutOfRangeException(string name) /// /// The argument name. /// The message to include in the exception. - /// Thrown with and . + /// Thrown with the specified parameters. [DoesNotReturn] public static void ThrowArgumentOutOfRangeException(string name, string message) { @@ -91,7 +91,7 @@ public static void ThrowArgumentOutOfRangeException(string name, string message) /// The argument name. /// The current argument value. /// The message to include in the exception. - /// Thrown with , and . + /// Thrown with the specified parameters. [DoesNotReturn] public static void ThrowArgumentOutOfRangeException(string name, object value, string message) { @@ -102,7 +102,7 @@ public static void ThrowArgumentOutOfRangeException(string name, object value, s /// Throws a new . /// /// The message to include in the exception. - /// Thrown with . + /// Thrown with the specified parameter. [DoesNotReturn] public static void ThrowFormatException(string message) { @@ -113,7 +113,7 @@ public static void ThrowFormatException(string message) /// Throws a new . /// /// The message to include in the exception. - /// Thrown with . + /// Thrown with the specified parameter. [DoesNotReturn] public static void ThrowInsufficientMemoryException(string message) { @@ -124,7 +124,7 @@ public static void ThrowInsufficientMemoryException(string message) /// Throws a new . /// /// The message to include in the exception. - /// Thrown with . + /// Thrown with the specified parameter. [DoesNotReturn] public static void ThrowInvalidOperationException(string message) { @@ -135,7 +135,7 @@ public static void ThrowInvalidOperationException(string message) /// Throws a new . /// /// The message to include in the exception. - /// Thrown with . + /// Thrown with the specified parameter. [DoesNotReturn] public static void ThrowMissingFieldException(string message) { @@ -147,7 +147,7 @@ public static void ThrowMissingFieldException(string message) /// /// The target class being inspected. /// The target field being retrieved. - /// Thrown with and . + /// Thrown with the specified parameters. [DoesNotReturn] public static void ThrowMissingFieldException(string className, string fieldName) { @@ -158,7 +158,7 @@ public static void ThrowMissingFieldException(string className, string fieldName /// Throws a new . /// /// The message to include in the exception. - /// Thrown with . + /// Thrown with the specified parameter. [DoesNotReturn] public static void ThrowMissingMemberException(string message) { @@ -170,7 +170,7 @@ public static void ThrowMissingMemberException(string message) /// /// The target class being inspected. /// The target member being retrieved. - /// Thrown with and . + /// Thrown with the specified parameters. [DoesNotReturn] public static void ThrowMissingMemberException(string className, string memberName) { @@ -181,7 +181,7 @@ public static void ThrowMissingMemberException(string className, string memberNa /// Throws a new . /// /// The message to include in the exception. - /// Thrown with . + /// Thrown with the specified parameter. [DoesNotReturn] public static void ThrowMissingMethodException(string message) { @@ -193,7 +193,7 @@ public static void ThrowMissingMethodException(string message) /// /// The target class being inspected. /// The target method being retrieved. - /// Thrown with and . + /// Thrown with the specified parameters. [DoesNotReturn] public static void ThrowMissingMethodException(string className, string methodName) { @@ -204,7 +204,7 @@ public static void ThrowMissingMethodException(string className, string methodNa /// Throws a new . /// /// The message to include in the exception. - /// Thrown with . + /// Thrown with the specified parameter. [DoesNotReturn] public static void ThrowNotSupportedException(string message) { @@ -215,7 +215,7 @@ public static void ThrowNotSupportedException(string message) /// Throws a new . /// /// The name of the disposed object. - /// Thrown with . + /// Thrown with the specified parameter. [DoesNotReturn] public static void ThrowObjectDisposedException(string objectName) { @@ -227,7 +227,7 @@ public static void ThrowObjectDisposedException(string objectName) /// /// The name of the disposed object. /// The message to include in the exception. - /// Thrown with and . + /// Thrown with the specified parameters. [DoesNotReturn] public static void ThrowObjectDisposedException(string objectName, string message) { @@ -238,7 +238,7 @@ public static void ThrowObjectDisposedException(string objectName, string messag /// Throws a new . /// /// The message to include in the exception. - /// Thrown with . + /// Thrown with the specified parameter. [DoesNotReturn] public static void ThrowOperationCanceledException(string message) { @@ -249,7 +249,7 @@ public static void ThrowOperationCanceledException(string message) /// Throws a new . /// /// The in use. - /// Thrown with . + /// Thrown with the specified parameters. [DoesNotReturn] public static void ThrowOperationCanceledException(CancellationToken token) { @@ -257,11 +257,11 @@ public static void ThrowOperationCanceledException(CancellationToken token) } /// - /// Throws a new . + /// Throws a new . /// /// The message to include in the exception. /// The in use. - /// Thrown with and . + /// Thrown with the specified parameters. [DoesNotReturn] public static void ThrowThrowOperationCanceledException(string message, CancellationToken token) { @@ -272,7 +272,7 @@ public static void ThrowThrowOperationCanceledException(string message, Cancella /// Throws a new . /// /// The message to include in the exception. - /// Thrown with . + /// Thrown with the specified parameter. [DoesNotReturn] public static void ThrowPlatformNotSupportedException(string message) { @@ -283,7 +283,7 @@ public static void ThrowPlatformNotSupportedException(string message) /// Throws a new . /// /// The message to include in the exception. - /// Thrown with . + /// Thrown with the specified parameter. [DoesNotReturn] public static void ThrowTimeoutException(string message) { @@ -294,7 +294,7 @@ public static void ThrowTimeoutException(string message) /// Throws a new . /// /// The message to include in the exception. - /// Thrown with . + /// Thrown with the specified parameter. [DoesNotReturn] public static void ThrowUnauthorizedAccessException(string message) { From 0172ae5d674dc5b25982a7b05f98ef1565e36482 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 15 Jun 2020 02:44:17 +0200 Subject: [PATCH 08/19] Added overloads with inner exception parameters --- .../ThrowHelper.ThrowExceptions.cs | 206 ++++++++++++++++++ 1 file changed, 206 insertions(+) diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs index 5f2915dad6d..4de7230b12e 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs @@ -27,6 +27,18 @@ public static void ThrowArgumentException(string message) throw new ArgumentException(message); } + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowArgumentException(string message, Exception innerException) + { + throw new ArgumentException(message, innerException); + } + /// /// Throws a new . /// @@ -39,6 +51,19 @@ public static void ThrowArgumentException(string name, string message) throw new ArgumentException(message, name); } + /// + /// Throws a new . + /// + /// The argument name. + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowArgumentException(string name, string message, Exception innerException) + { + throw new ArgumentException(message, name, innerException); + } + /// /// Throws a new . /// @@ -50,6 +75,18 @@ public static void ThrowArgumentNullException(string name) throw new ArgumentNullException(name); } + /// + /// Throws a new . + /// + /// The argument name. + /// The inner to include. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowArgumentNullException(string name, Exception innerException) + { + throw new ArgumentNullException(name, innerException); + } + /// /// Throws a new . /// @@ -73,6 +110,18 @@ public static void ThrowArgumentOutOfRangeException(string name) throw new ArgumentOutOfRangeException(name); } + /// + /// Throws a new . + /// + /// The argument name. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeException(string name, Exception innerException) + { + throw new ArgumentOutOfRangeException(name, innerException); + } + /// /// Throws a new . /// @@ -109,6 +158,18 @@ public static void ThrowFormatException(string message) throw new FormatException(message); } + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowFormatException(string message, Exception innerException) + { + throw new FormatException(message, innerException); + } + /// /// Throws a new . /// @@ -120,6 +181,18 @@ public static void ThrowInsufficientMemoryException(string message) throw new InsufficientMemoryException(message); } + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowInsufficientMemoryException(string message, Exception innerException) + { + throw new InsufficientMemoryException(message, innerException); + } + /// /// Throws a new . /// @@ -131,6 +204,18 @@ public static void ThrowInvalidOperationException(string message) throw new InvalidOperationException(message); } + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowInvalidOperationException(string message, Exception innerException) + { + throw new InvalidOperationException(message, innerException); + } + /// /// Throws a new . /// @@ -142,6 +227,18 @@ public static void ThrowMissingFieldException(string message) throw new MissingFieldException(message); } + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowMissingFieldException(string message, Exception innerException) + { + throw new MissingFieldException(message, innerException); + } + /// /// Throws a new . /// @@ -165,6 +262,18 @@ public static void ThrowMissingMemberException(string message) throw new MissingMemberException(message); } + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowMissingMemberException(string message, Exception innerException) + { + throw new MissingMemberException(message, innerException); + } + /// /// Throws a new . /// @@ -188,6 +297,18 @@ public static void ThrowMissingMethodException(string message) throw new MissingMethodException(message); } + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowMissingMethodException(string message, Exception innerException) + { + throw new MissingMethodException(message, innerException); + } + /// /// Throws a new . /// @@ -211,6 +332,18 @@ public static void ThrowNotSupportedException(string message) throw new NotSupportedException(message); } + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowNotSupportedException(string message, Exception innerException) + { + throw new NotSupportedException(message, innerException); + } + /// /// Throws a new . /// @@ -222,6 +355,18 @@ public static void ThrowObjectDisposedException(string objectName) throw new ObjectDisposedException(objectName); } + /// + /// Throws a new . + /// + /// The name of the disposed object. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowObjectDisposedException(string objectName, Exception innerException) + { + throw new ObjectDisposedException(objectName, innerException); + } + /// /// Throws a new . /// @@ -245,6 +390,18 @@ public static void ThrowOperationCanceledException(string message) throw new OperationCanceledException(message); } + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowOperationCanceledException(string message, Exception innerException) + { + throw new OperationCanceledException(message, innerException); + } + /// /// Throws a new . /// @@ -268,6 +425,19 @@ public static void ThrowThrowOperationCanceledException(string message, Cancella throw new OperationCanceledException(message, token); } + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// The in use. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowThrowOperationCanceledException(string message, Exception innerException, CancellationToken token) + { + throw new OperationCanceledException(message, innerException, token); + } + /// /// Throws a new . /// @@ -279,6 +449,18 @@ public static void ThrowPlatformNotSupportedException(string message) throw new PlatformNotSupportedException(message); } + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowPlatformNotSupportedException(string message, Exception innerException) + { + throw new PlatformNotSupportedException(message, innerException); + } + /// /// Throws a new . /// @@ -290,6 +472,18 @@ public static void ThrowTimeoutException(string message) throw new TimeoutException(message); } + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowTimeoutException(string message, Exception innerException) + { + throw new TimeoutException(message, innerException); + } + /// /// Throws a new . /// @@ -301,6 +495,18 @@ public static void ThrowUnauthorizedAccessException(string message) throw new UnauthorizedAccessException(message); } + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowUnauthorizedAccessException(string message, Exception innerException) + { + throw new UnauthorizedAccessException(message, innerException); + } + /// /// Returns a formatted representation of the input value. /// From 9031384f5de671b734ea7f2037435db33687f5cc Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 15 Jun 2020 03:09:30 +0200 Subject: [PATCH 09/19] Added more exceptions --- .../ThrowHelper.ThrowExceptions.cs | 157 +++++++++++++++++- 1 file changed, 155 insertions(+), 2 deletions(-) diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs index 4de7230b12e..813c4f910f0 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs @@ -3,8 +3,11 @@ // See the LICENSE file in the project root for more information. using System; +using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; +using System.IO; +using System.Runtime.InteropServices; using System.Threading; #nullable enable @@ -147,6 +150,41 @@ public static void ThrowArgumentOutOfRangeException(string name, object value, s throw new ArgumentOutOfRangeException(name, value, message); } + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowExternalException(string message) + { + throw new ExternalException(message); + } + + /// + /// Throws a new . + /// + /// The argument name. + /// The inner to include. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowExternalException(string message, Exception innerException) + { + throw new ExternalException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The argument name. + /// The HRESULT of the errror to include. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowExternalException(string message, int error) + { + throw new ExternalException(message, error); + } + /// /// Throws a new . /// @@ -193,6 +231,29 @@ public static void ThrowInsufficientMemoryException(string message, Exception in throw new InsufficientMemoryException(message, innerException); } + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowInvalidDataException(string message) + { + throw new InvalidDataException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowInvalidDataException(string message, Exception innerException) + { + throw new InvalidDataException(message, innerException); + } + /// /// Throws a new . /// @@ -216,6 +277,29 @@ public static void ThrowInvalidOperationException(string message, Exception inne throw new InvalidOperationException(message, innerException); } + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowLockRecursionException(string message) + { + throw new LockRecursionException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowLockRecursionException(string message, Exception innerException) + { + throw new LockRecursionException(message, innerException); + } + /// /// Throws a new . /// @@ -420,7 +504,7 @@ public static void ThrowOperationCanceledException(CancellationToken token) /// The in use. /// Thrown with the specified parameters. [DoesNotReturn] - public static void ThrowThrowOperationCanceledException(string message, CancellationToken token) + public static void ThrowOperationCanceledException(string message, CancellationToken token) { throw new OperationCanceledException(message, token); } @@ -433,7 +517,7 @@ public static void ThrowThrowOperationCanceledException(string message, Cancella /// The in use. /// Thrown with the specified parameters. [DoesNotReturn] - public static void ThrowThrowOperationCanceledException(string message, Exception innerException, CancellationToken token) + public static void ThrowOperationCanceledException(string message, Exception innerException, CancellationToken token) { throw new OperationCanceledException(message, innerException, token); } @@ -461,6 +545,29 @@ public static void ThrowPlatformNotSupportedException(string message, Exception throw new PlatformNotSupportedException(message, innerException); } + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowSynchronizationLockException(string message) + { + throw new SynchronizationLockException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowSynchronizationLockException(string message, Exception innerException) + { + throw new SynchronizationLockException(message, innerException); + } + /// /// Throws a new . /// @@ -507,6 +614,52 @@ public static void ThrowUnauthorizedAccessException(string message, Exception in throw new UnauthorizedAccessException(message, innerException); } + /// + /// Throws a new . + /// + /// The Win32 error code associated with this exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowWin32Exception(int error) + { + throw new Win32Exception(error); + } + + /// + /// Throws a new . + /// + /// The Win32 error code associated with this exception. + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowWin32Exception(int error, string message) + { + throw new Win32Exception(error, message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowWin32Exception(string message) + { + throw new Win32Exception(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowWin32Exception(string message, Exception innerException) + { + throw new Win32Exception(message, innerException); + } + /// /// Returns a formatted representation of the input value. /// From 2cce132df5e306d15756f76de2ccd27929a0ac8a Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 17 Jun 2020 16:21:57 +0200 Subject: [PATCH 10/19] Added ArrayTypeMismatchException throw APIs --- .../ThrowHelper.ThrowExceptions.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs index 813c4f910f0..9890e1bb9ea 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs @@ -19,6 +19,29 @@ namespace Microsoft.Toolkit.Diagnostics /// public static partial class ThrowHelper { + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowArrayTypeMismatchException(string message) + { + throw new ArrayTypeMismatchException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowArrayTypeMismatchException(string message, Exception innerException) + { + throw new ArrayTypeMismatchException(message, innerException); + } + /// /// Throws a new . /// From 53c68410139ec2ef7eb24e075ee83ffffb0b2ad2 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 16 Jul 2020 02:21:11 +0200 Subject: [PATCH 11/19] Code refactoring, moved attributes to root --- .../Attributes/DoesNotReturnAttribute.cs | 0 .../Attributes/DoesNotReturnIfAttribute.cs | 0 .../Attributes/NotNullAttribute.cs | 0 .../Diagnostics/ThrowHelper.ThrowExceptions.cs | 17 ----------------- Microsoft.Toolkit/Diagnostics/ThrowHelper.cs | 17 +++++++++++++++++ 5 files changed, 17 insertions(+), 17 deletions(-) rename Microsoft.Toolkit/{Diagnostics => }/Attributes/DoesNotReturnAttribute.cs (100%) rename Microsoft.Toolkit/{Diagnostics => }/Attributes/DoesNotReturnIfAttribute.cs (100%) rename Microsoft.Toolkit/{Diagnostics => }/Attributes/NotNullAttribute.cs (100%) diff --git a/Microsoft.Toolkit/Diagnostics/Attributes/DoesNotReturnAttribute.cs b/Microsoft.Toolkit/Attributes/DoesNotReturnAttribute.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/Attributes/DoesNotReturnAttribute.cs rename to Microsoft.Toolkit/Attributes/DoesNotReturnAttribute.cs diff --git a/Microsoft.Toolkit/Diagnostics/Attributes/DoesNotReturnIfAttribute.cs b/Microsoft.Toolkit/Attributes/DoesNotReturnIfAttribute.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/Attributes/DoesNotReturnIfAttribute.cs rename to Microsoft.Toolkit/Attributes/DoesNotReturnIfAttribute.cs diff --git a/Microsoft.Toolkit/Diagnostics/Attributes/NotNullAttribute.cs b/Microsoft.Toolkit/Attributes/NotNullAttribute.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/Attributes/NotNullAttribute.cs rename to Microsoft.Toolkit/Attributes/NotNullAttribute.cs diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs index 9890e1bb9ea..d51c4362b19 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs @@ -5,7 +5,6 @@ using System; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; -using System.Diagnostics.Contracts; using System.IO; using System.Runtime.InteropServices; using System.Threading; @@ -682,21 +681,5 @@ public static void ThrowWin32Exception(string message, Exception innerException) { throw new Win32Exception(message, innerException); } - - /// - /// Returns a formatted representation of the input value. - /// - /// The input to format. - /// A formatted representation of to display in error messages. - [Pure] - private static string ToAssertString(this object? obj) - { - return obj switch - { - string _ => $"\"{obj}\"", - null => "null", - _ => $"<{obj}>" - }; - } } } diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs index d95e2320274..d27fc8aba7b 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs @@ -4,6 +4,7 @@ using System; using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; @@ -16,6 +17,22 @@ namespace Microsoft.Toolkit.Diagnostics /// public static partial class ThrowHelper { + /// + /// Returns a formatted representation of the input value. + /// + /// The input to format. + /// A formatted representation of to display in error messages. + [Pure] + private static string ToAssertString(this object? obj) + { + return obj switch + { + string _ => $"\"{obj}\"", + null => "null", + _ => $"<{obj}>" + }; + } + /// /// Throws an when (where is ) fails. /// From 443947d452aa0dd250d555de6fbe2d13c5ba44a6 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 21 Jul 2020 20:12:41 +0200 Subject: [PATCH 12/19] Improved XML summary for ThrowHelper class --- .../Diagnostics/Generated/ThrowHelper.Collection.g.cs | 2 +- .../Diagnostics/Generated/ThrowHelper.Collection.tt | 2 +- Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs | 2 +- Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs | 2 +- Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs | 2 +- Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs | 2 +- Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs | 2 +- Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs | 2 +- Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs | 2 +- Microsoft.Toolkit/Diagnostics/ThrowHelper.cs | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs index 8c9026be221..1994b5fcc8c 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs @@ -16,7 +16,7 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// public static partial class ThrowHelper { diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt index c52adafacda..731065134fc 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt @@ -13,7 +13,7 @@ using Microsoft.Toolkit.Extensions; namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// public static partial class ThrowHelper { diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs index 64553be2387..9ef29cbd440 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs @@ -12,7 +12,7 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// public static partial class ThrowHelper { diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs index aa45dc82702..030ede72c30 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs @@ -12,7 +12,7 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// public static partial class ThrowHelper { diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs index fef5019e6e6..f249e812dc4 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs @@ -12,7 +12,7 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// public static partial class ThrowHelper { diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs index b8cfebe6b6e..442ea37c063 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs @@ -13,7 +13,7 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// public static partial class ThrowHelper { diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs index 8de060c0b1e..bfcbed6f835 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs @@ -11,7 +11,7 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// public static partial class ThrowHelper { diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs index 2689a32cec2..09f8db9c14b 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs @@ -13,7 +13,7 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// public static partial class ThrowHelper { diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs index d51c4362b19..103c3ef12ad 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs @@ -14,7 +14,7 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// public static partial class ThrowHelper { diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs index d27fc8aba7b..0ba836dc488 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs @@ -13,7 +13,7 @@ namespace Microsoft.Toolkit.Diagnostics { /// - /// Helper methods to throw exceptions + /// Helper methods to efficiently throw exceptions. /// public static partial class ThrowHelper { From f70ae0cdb29055d0cf1637f9c43163af9900524d Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 21 Jul 2020 22:59:56 +0200 Subject: [PATCH 13/19] Added [StackTraceHidden] attribute --- .../Attributes/StackTraceHiddenAttribute.cs | 16 ++++ .../Generated/ThrowHelper.Collection.g.cs | 89 +++++++++++++++++++ .../Generated/ThrowHelper.Collection.tt | 12 +++ .../ThrowHelper.Collection.Generic.cs | 4 + .../ThrowHelper.Comparable.Generic.cs | 15 ++++ .../ThrowHelper.Comparable.Numeric.cs | 9 ++ .../Diagnostics/ThrowHelper.IO.cs | 5 ++ .../Diagnostics/ThrowHelper.String.cs | 19 ++++ .../Diagnostics/ThrowHelper.Tasks.cs | 11 +++ .../ThrowHelper.ThrowExceptions.cs | 58 ++++++++++++ Microsoft.Toolkit/Diagnostics/ThrowHelper.cs | 19 ++++ 11 files changed, 257 insertions(+) create mode 100644 Microsoft.Toolkit/Attributes/StackTraceHiddenAttribute.cs diff --git a/Microsoft.Toolkit/Attributes/StackTraceHiddenAttribute.cs b/Microsoft.Toolkit/Attributes/StackTraceHiddenAttribute.cs new file mode 100644 index 00000000000..c176fb09741 --- /dev/null +++ b/Microsoft.Toolkit/Attributes/StackTraceHiddenAttribute.cs @@ -0,0 +1,16 @@ +// 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. + +namespace System.Diagnostics +{ + /// + /// Attribute to add to non-returning throw only methods, + /// to restore the stack trace back to what it would be if the throw was in-place + /// + /// Internal copy of the CoreCLR attribute. + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Struct, Inherited = false)] + internal sealed class StackTraceHiddenAttribute : Attribute + { + } +} \ No newline at end of file diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs index 1994b5fcc8c..34d0ea8ed3f 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs @@ -6,6 +6,7 @@ // ===================== using System; +using System.Diagnostics; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; @@ -25,6 +26,7 @@ public static partial class ThrowHelper /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(Span span, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must be empty, had a size of {span.Length.ToAssertString()}"); @@ -35,6 +37,7 @@ internal static void ThrowArgumentExceptionForIsEmpty(Span span, string na /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size equal to {size}, had a size of {span.Length.ToAssertString()}"); @@ -45,6 +48,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(Span span, in /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size not equal to {size}, had a size of {span.Length.ToAssertString()}"); @@ -55,6 +59,7 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(Span span, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}"); @@ -65,6 +70,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(Span span /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}"); @@ -75,6 +81,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Spa /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size less than {size}, had a size of {span.Length.ToAssertString()}"); @@ -85,6 +92,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(Span span, i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size less than or equal to {size}, had a size of {span.Length.ToAssertString()}"); @@ -95,6 +103,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(Span source, Span destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -105,6 +114,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(Span source, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span source, Span destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -115,6 +125,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Span span, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {span.Length.ToAssertString()} to be a valid index for the target collection ({typeof(Span).ToTypeString()}), was {index.ToAssertString()}"); @@ -125,6 +136,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Span span, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {span.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(Span).ToTypeString()}), was {index.ToAssertString()}"); @@ -135,6 +147,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(ReadOnlySpan span, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must be empty, had a size of {span.Length.ToAssertString()}"); @@ -145,6 +158,7 @@ internal static void ThrowArgumentExceptionForIsEmpty(ReadOnlySpan span, s /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size equal to {size}, had a size of {span.Length.ToAssertString()}"); @@ -155,6 +169,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size not equal to {size}, had a size of {span.Length.ToAssertString()}"); @@ -165,6 +180,7 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlySpan< /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}"); @@ -175,6 +191,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlySpan /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}"); @@ -185,6 +202,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Rea /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than {size}, had a size of {span.Length.ToAssertString()}"); @@ -195,6 +213,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlySpan /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than or equal to {size}, had a size of {span.Length.ToAssertString()}"); @@ -205,6 +224,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOn /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan source, Span destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -215,6 +235,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlySpan source, Span destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -225,6 +246,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOn /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlySpan span, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {span.Length.ToAssertString()} to be a valid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {index.ToAssertString()}"); @@ -235,6 +257,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlySpan span, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {span.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {index.ToAssertString()}"); @@ -245,6 +268,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(Memory memory, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must be empty, had a size of {memory.Length.ToAssertString()}"); @@ -255,6 +279,7 @@ internal static void ThrowArgumentExceptionForIsEmpty(Memory memory, strin /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size equal to {size}, had a size of {memory.Length.ToAssertString()}"); @@ -265,6 +290,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(Memory memory /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size not equal to {size}, had a size of {memory.Length.ToAssertString()}"); @@ -275,6 +301,7 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(Memory mem /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}"); @@ -285,6 +312,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(Memory me /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}"); @@ -295,6 +323,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Mem /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size less than {size}, had a size of {memory.Length.ToAssertString()}"); @@ -305,6 +334,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(Memory memor /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size less than or equal to {size}, had a size of {memory.Length.ToAssertString()}"); @@ -315,6 +345,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(Memory source, Memory destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -325,6 +356,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(Memory source /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory source, Memory destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -335,6 +367,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Memory memory, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {memory.Length.ToAssertString()} to be a valid index for the target collection ({typeof(Memory).ToTypeString()}), was {index.ToAssertString()}"); @@ -345,6 +378,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Memory memory, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {memory.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(Memory).ToTypeString()}), was {index.ToAssertString()}"); @@ -355,6 +389,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(ReadOnlyMemory memory, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must be empty, had a size of {memory.Length.ToAssertString()}"); @@ -365,6 +400,7 @@ internal static void ThrowArgumentExceptionForIsEmpty(ReadOnlyMemory memor /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size equal to {size}, had a size of {memory.Length.ToAssertString()}"); @@ -375,6 +411,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size not equal to {size}, had a size of {memory.Length.ToAssertString()}"); @@ -385,6 +422,7 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlyMemor /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}"); @@ -395,6 +433,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlyMemo /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}"); @@ -405,6 +444,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Rea /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than {size}, had a size of {memory.Length.ToAssertString()}"); @@ -415,6 +455,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlyMemory< /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than or equal to {size}, had a size of {memory.Length.ToAssertString()}"); @@ -425,6 +466,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOn /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory source, Memory destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -435,6 +477,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlyMemory source, Memory destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -445,6 +488,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOn /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlyMemory memory, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {memory.Length.ToAssertString()} to be a valid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {index.ToAssertString()}"); @@ -455,6 +499,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlyMemory memory, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {memory.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {index.ToAssertString()}"); @@ -465,6 +510,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(T[] array, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must be empty, had a size of {array.Length.ToAssertString()}"); @@ -475,6 +521,7 @@ internal static void ThrowArgumentExceptionForIsEmpty(T[] array, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size equal to {size}, had a size of {array.Length.ToAssertString()}"); @@ -485,6 +532,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(T[] array, int s /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size not equal to {size}, had a size of {array.Length.ToAssertString()}"); @@ -495,6 +543,7 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(T[] array, in /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size over {size}, had a size of {array.Length.ToAssertString()}"); @@ -505,6 +554,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(T[] array, i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size of at least {size}, had a size of {array.Length.ToAssertString()}"); @@ -515,6 +565,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(T[] /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size less than {size}, had a size of {array.Length.ToAssertString()}"); @@ -525,6 +576,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(T[] array, int /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size less than or equal to {size}, had a size of {array.Length.ToAssertString()}"); @@ -535,6 +587,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] ar /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(T[] source, T[] destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -545,6 +598,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(T[] source, T[] /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] source, T[] destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -555,6 +609,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] so /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, T[] array, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {array.Length.ToAssertString()} to be a valid index for the target collection ({typeof(T[]).ToTypeString()}), was {index.ToAssertString()}"); @@ -565,6 +620,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, T[] array, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {array.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(T[]).ToTypeString()}), was {index.ToAssertString()}"); @@ -575,6 +631,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(List list, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must be empty, had a size of {list.Count.ToAssertString()}"); @@ -585,6 +642,7 @@ internal static void ThrowArgumentExceptionForIsEmpty(List list, string na /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size equal to {size}, had a size of {list.Count.ToAssertString()}"); @@ -595,6 +653,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(List list, in /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size not equal to {size}, had a size of {list.Count.ToAssertString()}"); @@ -605,6 +664,7 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(List list, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size over {size}, had a size of {list.Count.ToAssertString()}"); @@ -615,6 +675,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(List list /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size of at least {size}, had a size of {list.Count.ToAssertString()}"); @@ -625,6 +686,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Lis /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size less than {size}, had a size of {list.Count.ToAssertString()}"); @@ -635,6 +697,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(List list, i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size less than or equal to {size}, had a size of {list.Count.ToAssertString()}"); @@ -645,6 +708,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(List source, List destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); @@ -655,6 +719,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(List source, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List source, List destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size less than or equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); @@ -665,6 +730,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, List list, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {list.Count.ToAssertString()} to be a valid index for the target collection ({typeof(List).ToTypeString()}), was {index.ToAssertString()}"); @@ -675,6 +741,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, List list, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {list.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(List).ToTypeString()}), was {index.ToAssertString()}"); @@ -685,6 +752,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(ICollection collection, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must be empty, had a size of {collection.Count.ToAssertString()}"); @@ -695,6 +763,7 @@ internal static void ThrowArgumentExceptionForIsEmpty(ICollection collecti /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size equal to {size}, had a size of {collection.Count.ToAssertString()}"); @@ -705,6 +774,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection c /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size not equal to {size}, had a size of {collection.Count.ToAssertString()}"); @@ -715,6 +785,7 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ICollection [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}"); @@ -725,6 +796,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ICollection< /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}"); @@ -735,6 +807,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ICo /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size less than {size}, had a size of {collection.Count.ToAssertString()}"); @@ -745,6 +818,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(ICollection /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size less than or equal to {size}, had a size of {collection.Count.ToAssertString()}"); @@ -755,6 +829,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IColle /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection source, ICollection destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); @@ -765,6 +840,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection s /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollection source, ICollection destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size less than or equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); @@ -775,6 +851,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IColle /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ICollection collection, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {collection.Count.ToAssertString()} to be a valid index for the target collection ({typeof(ICollection).ToTypeString()}), was {index.ToAssertString()}"); @@ -785,6 +862,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ICollection collection, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {collection.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(ICollection).ToTypeString()}), was {index.ToAssertString()}"); @@ -795,6 +873,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(IReadOnlyCollection collection, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must be empty, had a size of {collection.Count.ToAssertString()}"); @@ -805,6 +884,7 @@ internal static void ThrowArgumentExceptionForIsEmpty(IReadOnlyCollection /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size equal to {size}, had a size of {collection.Count.ToAssertString()}"); @@ -815,6 +895,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollect /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size not equal to {size}, had a size of {collection.Count.ToAssertString()}"); @@ -825,6 +906,7 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(IReadOnlyColl /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}"); @@ -835,6 +917,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(IReadOnlyCol /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}"); @@ -845,6 +928,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(IRe /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than {size}, had a size of {collection.Count.ToAssertString()}"); @@ -855,6 +939,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(IReadOnlyCollec /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than or equal to {size}, had a size of {collection.Count.ToAssertString()}"); @@ -865,6 +950,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadO /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollection source, ICollection destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); @@ -875,6 +961,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollect /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnlyCollection source, ICollection destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than or equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); @@ -885,6 +972,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadO /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, IReadOnlyCollection collection, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {collection.Count.ToAssertString()} to be a valid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {index.ToAssertString()}"); @@ -895,6 +983,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, IReadOnlyCollection collection, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {collection.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {index.ToAssertString()}"); diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt index 731065134fc..99c138d35be 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. <#@include file="TypeInfo.ttinclude" #> using System; +using System.Diagnostics; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; @@ -26,6 +27,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(<#=item.Type#> <#=item.Name#>, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must be empty, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); @@ -36,6 +38,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); @@ -46,6 +49,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size not equal to {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); @@ -56,6 +60,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size over {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); @@ -66,6 +71,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size of at least {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); @@ -76,6 +82,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); @@ -86,6 +93,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); @@ -96,6 +104,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {destination.<#=item.Size#>.ToAssertString()} (the destination), had a size of {source.<#=item.Size#>.ToAssertString()}"); @@ -106,6 +115,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {destination.<#=item.Size#>.ToAssertString()} (the destination), had a size of {source.<#=item.Size#>.ToAssertString()}"); @@ -116,6 +126,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {<#=item.Name#>.<#=item.Size#>.ToAssertString()} to be a valid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {index.ToAssertString()}"); @@ -126,6 +137,7 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {<#=item.Name#>.<#=item.Size#>.ToAssertString()} to be an invalid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {index.ToAssertString()}"); diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs index 9ef29cbd440..5e0df16cc5f 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; @@ -23,6 +24,7 @@ public static partial class ThrowHelper /// This method is needed because can't be used as a generic type parameter. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must not be empty"); @@ -35,6 +37,7 @@ internal static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) /// This method is needed because can't be used as a generic type parameter. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must not be empty"); @@ -46,6 +49,7 @@ internal static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(stri /// The item of items in the input collection. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotEmpty(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be empty"); diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs index 030ede72c30..23d86f9319b 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; @@ -22,6 +23,7 @@ public static partial class ThrowHelper /// The type of value type being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsDefault(T value, string name) where T : struct { @@ -34,6 +36,7 @@ internal static void ThrowArgumentExceptionForIsDefault(T value, string name) /// The type of value type being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotDefault(string name) where T : struct { @@ -46,6 +49,7 @@ internal static void ThrowArgumentExceptionForIsNotDefault(string name) /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEqualTo(T value, T target, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be equal to {target.ToAssertString()}, was {value.ToAssertString()}"); @@ -57,6 +61,7 @@ internal static void ThrowArgumentExceptionForIsEqualTo(T value, T target, st /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be equal to {target.ToAssertString()}, was {value.ToAssertString()}"); @@ -68,6 +73,7 @@ internal static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T maximum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than {maximum.ToAssertString()}, was {value.ToAssertString()}"); @@ -79,6 +85,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T value, T maximum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than or equal to {maximum.ToAssertString()}, was {value.ToAssertString()}"); @@ -90,6 +97,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value, T minimum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than {minimum.ToAssertString()}, was {value.ToAssertString()}"); @@ -101,6 +109,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(T value, T minimum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than or equal to {minimum.ToAssertString()}, was {value.ToAssertString()}"); @@ -112,6 +121,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualToThe type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); @@ -123,6 +133,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); @@ -134,6 +145,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); @@ -145,6 +157,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); @@ -156,6 +169,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); @@ -167,6 +181,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs index f249e812dc4..d3286382b1e 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; @@ -21,6 +22,7 @@ public static partial class ThrowHelper /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsCloseTo(int value, int target, uint delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(int).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((double)((long)value - target)).ToAssertString()}"); @@ -31,6 +33,7 @@ internal static void ThrowArgumentExceptionForIsCloseTo(int value, int target, u /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotCloseTo(int value, int target, uint delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(int).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((double)((long)value - target)).ToAssertString()}"); @@ -41,6 +44,7 @@ internal static void ThrowArgumentExceptionForIsNotCloseTo(int value, int target /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsCloseTo(long value, long target, ulong delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(long).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((decimal)value - target).ToAssertString()}"); @@ -51,6 +55,7 @@ internal static void ThrowArgumentExceptionForIsCloseTo(long value, long target, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotCloseTo(long value, long target, ulong delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(long).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((decimal)value - target).ToAssertString()}"); @@ -61,6 +66,7 @@ internal static void ThrowArgumentExceptionForIsNotCloseTo(long value, long targ /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsCloseTo(float value, float target, float delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(float).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); @@ -71,6 +77,7 @@ internal static void ThrowArgumentExceptionForIsCloseTo(float value, float targe /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotCloseTo(float value, float target, float delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(float).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); @@ -81,6 +88,7 @@ internal static void ThrowArgumentExceptionForIsNotCloseTo(float value, float ta /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsCloseTo(double value, double target, double delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(double).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); @@ -91,6 +99,7 @@ internal static void ThrowArgumentExceptionForIsCloseTo(double value, double tar /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotCloseTo(double value, double target, double delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(double).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs index 442ea37c063..8e0655ed217 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Runtime.CompilerServices; @@ -22,6 +23,7 @@ public static partial class ThrowHelper /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForCanRead(Stream stream, string name) { ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support reading"); @@ -32,6 +34,7 @@ internal static void ThrowArgumentExceptionForCanRead(Stream stream, string name /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForCanWrite(Stream stream, string name) { ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support writing"); @@ -42,6 +45,7 @@ internal static void ThrowArgumentExceptionForCanWrite(Stream stream, string nam /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForCanSeek(Stream stream, string name) { ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support seeking"); @@ -52,6 +56,7 @@ internal static void ThrowArgumentExceptionForCanSeek(Stream stream, string name /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsAtStartPosition(Stream stream, string name) { ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) must be at position {0.ToAssertString()}, was at {stream.Position.ToAssertString()}"); diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs index bfcbed6f835..24d48bfeb36 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; @@ -20,6 +21,7 @@ public static partial class ThrowHelper /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNullOrEmpty(string? text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be null or empty, was {text.ToAssertString()}"); @@ -30,6 +32,7 @@ internal static void ThrowArgumentExceptionForIsNullOrEmpty(string? text, string /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotNullOrEmpty(string? text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be null or empty, was {(text is null ? "null" : "empty")}"); @@ -40,6 +43,7 @@ internal static void ThrowArgumentExceptionForIsNotNullOrEmpty(string? text, str /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNullOrWhitespace(string? text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be null or whitespace, was {text.ToAssertString()}"); @@ -50,6 +54,7 @@ internal static void ThrowArgumentExceptionForIsNullOrWhitespace(string? text, s /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotNullOrWhitespace(string? text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be null or whitespace, was {(text is null ? "null" : "whitespace")}"); @@ -60,6 +65,7 @@ internal static void ThrowArgumentExceptionForIsNotNullOrWhitespace(string? text /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(string text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be empty, was {text.ToAssertString()}"); @@ -70,6 +76,7 @@ internal static void ThrowArgumentExceptionForIsEmpty(string text, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotEmpty(string text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be empty"); @@ -80,6 +87,7 @@ internal static void ThrowArgumentExceptionForIsNotEmpty(string text, string nam /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsWhitespace(string text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be whitespace, was {text.ToAssertString()}"); @@ -90,6 +98,7 @@ internal static void ThrowArgumentExceptionForIsWhitespace(string text, string n /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotWhitespace(string text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be whitespace, was {text.ToAssertString()}"); @@ -100,6 +109,7 @@ internal static void ThrowArgumentExceptionForIsNotWhitespace(string text, strin /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size equal to {size}, had a size of {text.Length} and was {text.ToAssertString()}"); @@ -110,6 +120,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int si /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not have a size equal to {size}, was {text.ToAssertString()}"); @@ -120,6 +131,7 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(string text, int /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size over {size}, had a size of {text.Length} and was {text.ToAssertString()}"); @@ -130,6 +142,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(string text, in /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size of at least {size}, had a size of {text.Length} and was {text.ToAssertString()}"); @@ -140,6 +153,7 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(string /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size less than {size}, had a size of {text.Length} and was {text.ToAssertString()}"); @@ -150,6 +164,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(string text, int s /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size less than or equal to {size}, had a size of {text.Length} and was {text.ToAssertString()}"); @@ -160,6 +175,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string te /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(string source, string destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} (string) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -170,6 +186,7 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(string source, stri /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string source, string destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} (string) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -180,6 +197,7 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string so /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, string text, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {text.Length.ToAssertString()} to be a valid index for the target string, was {index.ToAssertString()}"); @@ -190,6 +208,7 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, string text, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {text.Length.ToAssertString()} to be an invalid index for the target string, was {index.ToAssertString()}"); diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs index 09f8db9c14b..69ee19403db 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Threading.Tasks; @@ -22,6 +23,7 @@ public static partial class ThrowHelper /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsCompleted(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be completed, had status {task.Status.ToAssertString()}"); @@ -32,6 +34,7 @@ internal static void ThrowArgumentExceptionForIsCompleted(Task task, string name /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotCompleted(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be completed, had status {task.Status.ToAssertString()}"); @@ -42,6 +45,7 @@ internal static void ThrowArgumentExceptionForIsNotCompleted(Task task, string n /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsCompletedSuccessfully(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be completed successfully, had status {task.Status.ToAssertString()}"); @@ -52,6 +56,7 @@ internal static void ThrowArgumentExceptionForIsCompletedSuccessfully(Task task, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotCompletedSuccessfully(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be completed successfully, had status {task.Status.ToAssertString()}"); @@ -62,6 +67,7 @@ internal static void ThrowArgumentExceptionForIsNotCompletedSuccessfully(Task ta /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsFaulted(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be faulted, had status {task.Status.ToAssertString()}"); @@ -72,6 +78,7 @@ internal static void ThrowArgumentExceptionForIsFaulted(Task task, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotFaulted(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be faulted, had status {task.Status.ToAssertString()}"); @@ -82,6 +89,7 @@ internal static void ThrowArgumentExceptionForIsNotFaulted(Task task, string nam /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsCanceled(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be canceled, had status {task.Status.ToAssertString()}"); @@ -92,6 +100,7 @@ internal static void ThrowArgumentExceptionForIsCanceled(Task task, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotCanceled(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be canceled, had status {task.Status.ToAssertString()}"); @@ -102,6 +111,7 @@ internal static void ThrowArgumentExceptionForIsNotCanceled(Task task, string na /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasStatusEqualTo(Task task, TaskStatus status, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must have status {status}, had status {task.Status.ToAssertString()}"); @@ -112,6 +122,7 @@ internal static void ThrowArgumentExceptionForHasStatusEqualTo(Task task, TaskSt /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForHasStatusNotEqualTo(Task task, TaskStatus status, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not have status {status.ToAssertString()}"); diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs index 103c3ef12ad..2b03427f10e 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs @@ -4,6 +4,7 @@ using System; using System.ComponentModel; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Runtime.InteropServices; @@ -24,6 +25,7 @@ public static partial class ThrowHelper /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowArrayTypeMismatchException(string message) { throw new ArrayTypeMismatchException(message); @@ -36,6 +38,7 @@ public static void ThrowArrayTypeMismatchException(string message) /// The inner to include. /// Thrown with the specified parameters. [DoesNotReturn] + [StackTraceHidden] public static void ThrowArrayTypeMismatchException(string message, Exception innerException) { throw new ArrayTypeMismatchException(message, innerException); @@ -47,6 +50,7 @@ public static void ThrowArrayTypeMismatchException(string message, Exception inn /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowArgumentException(string message) { throw new ArgumentException(message); @@ -59,6 +63,7 @@ public static void ThrowArgumentException(string message) /// The inner to include. /// Thrown with the specified parameters. [DoesNotReturn] + [StackTraceHidden] public static void ThrowArgumentException(string message, Exception innerException) { throw new ArgumentException(message, innerException); @@ -71,6 +76,7 @@ public static void ThrowArgumentException(string message, Exception innerExcepti /// The message to include in the exception. /// Thrown with the specified parameters. [DoesNotReturn] + [StackTraceHidden] public static void ThrowArgumentException(string name, string message) { throw new ArgumentException(message, name); @@ -84,6 +90,7 @@ public static void ThrowArgumentException(string name, string message) /// The inner to include. /// Thrown with the specified parameters. [DoesNotReturn] + [StackTraceHidden] public static void ThrowArgumentException(string name, string message, Exception innerException) { throw new ArgumentException(message, name, innerException); @@ -95,6 +102,7 @@ public static void ThrowArgumentException(string name, string message, Exception /// The argument name. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowArgumentNullException(string name) { throw new ArgumentNullException(name); @@ -107,6 +115,7 @@ public static void ThrowArgumentNullException(string name) /// The inner to include. /// Thrown with the specified parameters. [DoesNotReturn] + [StackTraceHidden] public static void ThrowArgumentNullException(string name, Exception innerException) { throw new ArgumentNullException(name, innerException); @@ -119,6 +128,7 @@ public static void ThrowArgumentNullException(string name, Exception innerExcept /// The message to include in the exception. /// Thrown with the specified parameters. [DoesNotReturn] + [StackTraceHidden] public static void ThrowArgumentNullException(string name, string message) { throw new ArgumentNullException(name, message); @@ -130,6 +140,7 @@ public static void ThrowArgumentNullException(string name, string message) /// The argument name. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowArgumentOutOfRangeException(string name) { throw new ArgumentOutOfRangeException(name); @@ -142,6 +153,7 @@ public static void ThrowArgumentOutOfRangeException(string name) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowArgumentOutOfRangeException(string name, Exception innerException) { throw new ArgumentOutOfRangeException(name, innerException); @@ -154,6 +166,7 @@ public static void ThrowArgumentOutOfRangeException(string name, Exception inner /// The message to include in the exception. /// Thrown with the specified parameters. [DoesNotReturn] + [StackTraceHidden] public static void ThrowArgumentOutOfRangeException(string name, string message) { throw new ArgumentOutOfRangeException(name, message); @@ -167,6 +180,7 @@ public static void ThrowArgumentOutOfRangeException(string name, string message) /// The message to include in the exception. /// Thrown with the specified parameters. [DoesNotReturn] + [StackTraceHidden] public static void ThrowArgumentOutOfRangeException(string name, object value, string message) { throw new ArgumentOutOfRangeException(name, value, message); @@ -178,6 +192,7 @@ public static void ThrowArgumentOutOfRangeException(string name, object value, s /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowExternalException(string message) { throw new ExternalException(message); @@ -190,6 +205,7 @@ public static void ThrowExternalException(string message) /// The inner to include. /// Thrown with the specified parameters. [DoesNotReturn] + [StackTraceHidden] public static void ThrowExternalException(string message, Exception innerException) { throw new ExternalException(message, innerException); @@ -202,6 +218,7 @@ public static void ThrowExternalException(string message, Exception innerExcepti /// The HRESULT of the errror to include. /// Thrown with the specified parameters. [DoesNotReturn] + [StackTraceHidden] public static void ThrowExternalException(string message, int error) { throw new ExternalException(message, error); @@ -213,6 +230,7 @@ public static void ThrowExternalException(string message, int error) /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowFormatException(string message) { throw new FormatException(message); @@ -225,6 +243,7 @@ public static void ThrowFormatException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowFormatException(string message, Exception innerException) { throw new FormatException(message, innerException); @@ -236,6 +255,7 @@ public static void ThrowFormatException(string message, Exception innerException /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowInsufficientMemoryException(string message) { throw new InsufficientMemoryException(message); @@ -248,6 +268,7 @@ public static void ThrowInsufficientMemoryException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowInsufficientMemoryException(string message, Exception innerException) { throw new InsufficientMemoryException(message, innerException); @@ -259,6 +280,7 @@ public static void ThrowInsufficientMemoryException(string message, Exception in /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowInvalidDataException(string message) { throw new InvalidDataException(message); @@ -271,6 +293,7 @@ public static void ThrowInvalidDataException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowInvalidDataException(string message, Exception innerException) { throw new InvalidDataException(message, innerException); @@ -282,6 +305,7 @@ public static void ThrowInvalidDataException(string message, Exception innerExce /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowInvalidOperationException(string message) { throw new InvalidOperationException(message); @@ -294,6 +318,7 @@ public static void ThrowInvalidOperationException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowInvalidOperationException(string message, Exception innerException) { throw new InvalidOperationException(message, innerException); @@ -305,6 +330,7 @@ public static void ThrowInvalidOperationException(string message, Exception inne /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowLockRecursionException(string message) { throw new LockRecursionException(message); @@ -317,6 +343,7 @@ public static void ThrowLockRecursionException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowLockRecursionException(string message, Exception innerException) { throw new LockRecursionException(message, innerException); @@ -328,6 +355,7 @@ public static void ThrowLockRecursionException(string message, Exception innerEx /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowMissingFieldException(string message) { throw new MissingFieldException(message); @@ -340,6 +368,7 @@ public static void ThrowMissingFieldException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowMissingFieldException(string message, Exception innerException) { throw new MissingFieldException(message, innerException); @@ -352,6 +381,7 @@ public static void ThrowMissingFieldException(string message, Exception innerExc /// The target field being retrieved. /// Thrown with the specified parameters. [DoesNotReturn] + [StackTraceHidden] public static void ThrowMissingFieldException(string className, string fieldName) { throw new MissingFieldException(className, fieldName); @@ -363,6 +393,7 @@ public static void ThrowMissingFieldException(string className, string fieldName /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowMissingMemberException(string message) { throw new MissingMemberException(message); @@ -375,6 +406,7 @@ public static void ThrowMissingMemberException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowMissingMemberException(string message, Exception innerException) { throw new MissingMemberException(message, innerException); @@ -387,6 +419,7 @@ public static void ThrowMissingMemberException(string message, Exception innerEx /// The target member being retrieved. /// Thrown with the specified parameters. [DoesNotReturn] + [StackTraceHidden] public static void ThrowMissingMemberException(string className, string memberName) { throw new MissingMemberException(className, memberName); @@ -398,6 +431,7 @@ public static void ThrowMissingMemberException(string className, string memberNa /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowMissingMethodException(string message) { throw new MissingMethodException(message); @@ -410,6 +444,7 @@ public static void ThrowMissingMethodException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowMissingMethodException(string message, Exception innerException) { throw new MissingMethodException(message, innerException); @@ -422,6 +457,7 @@ public static void ThrowMissingMethodException(string message, Exception innerEx /// The target method being retrieved. /// Thrown with the specified parameters. [DoesNotReturn] + [StackTraceHidden] public static void ThrowMissingMethodException(string className, string methodName) { throw new MissingMethodException(className, methodName); @@ -433,6 +469,7 @@ public static void ThrowMissingMethodException(string className, string methodNa /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowNotSupportedException(string message) { throw new NotSupportedException(message); @@ -445,6 +482,7 @@ public static void ThrowNotSupportedException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowNotSupportedException(string message, Exception innerException) { throw new NotSupportedException(message, innerException); @@ -456,6 +494,7 @@ public static void ThrowNotSupportedException(string message, Exception innerExc /// The name of the disposed object. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowObjectDisposedException(string objectName) { throw new ObjectDisposedException(objectName); @@ -468,6 +507,7 @@ public static void ThrowObjectDisposedException(string objectName) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowObjectDisposedException(string objectName, Exception innerException) { throw new ObjectDisposedException(objectName, innerException); @@ -480,6 +520,7 @@ public static void ThrowObjectDisposedException(string objectName, Exception inn /// The message to include in the exception. /// Thrown with the specified parameters. [DoesNotReturn] + [StackTraceHidden] public static void ThrowObjectDisposedException(string objectName, string message) { throw new ObjectDisposedException(objectName, message); @@ -491,6 +532,7 @@ public static void ThrowObjectDisposedException(string objectName, string messag /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowOperationCanceledException(string message) { throw new OperationCanceledException(message); @@ -503,6 +545,7 @@ public static void ThrowOperationCanceledException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowOperationCanceledException(string message, Exception innerException) { throw new OperationCanceledException(message, innerException); @@ -514,6 +557,7 @@ public static void ThrowOperationCanceledException(string message, Exception inn /// The in use. /// Thrown with the specified parameters. [DoesNotReturn] + [StackTraceHidden] public static void ThrowOperationCanceledException(CancellationToken token) { throw new OperationCanceledException(token); @@ -526,6 +570,7 @@ public static void ThrowOperationCanceledException(CancellationToken token) /// The in use. /// Thrown with the specified parameters. [DoesNotReturn] + [StackTraceHidden] public static void ThrowOperationCanceledException(string message, CancellationToken token) { throw new OperationCanceledException(message, token); @@ -539,6 +584,7 @@ public static void ThrowOperationCanceledException(string message, CancellationT /// The in use. /// Thrown with the specified parameters. [DoesNotReturn] + [StackTraceHidden] public static void ThrowOperationCanceledException(string message, Exception innerException, CancellationToken token) { throw new OperationCanceledException(message, innerException, token); @@ -550,6 +596,7 @@ public static void ThrowOperationCanceledException(string message, Exception inn /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowPlatformNotSupportedException(string message) { throw new PlatformNotSupportedException(message); @@ -562,6 +609,7 @@ public static void ThrowPlatformNotSupportedException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowPlatformNotSupportedException(string message, Exception innerException) { throw new PlatformNotSupportedException(message, innerException); @@ -573,6 +621,7 @@ public static void ThrowPlatformNotSupportedException(string message, Exception /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowSynchronizationLockException(string message) { throw new SynchronizationLockException(message); @@ -585,6 +634,7 @@ public static void ThrowSynchronizationLockException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowSynchronizationLockException(string message, Exception innerException) { throw new SynchronizationLockException(message, innerException); @@ -596,6 +646,7 @@ public static void ThrowSynchronizationLockException(string message, Exception i /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowTimeoutException(string message) { throw new TimeoutException(message); @@ -608,6 +659,7 @@ public static void ThrowTimeoutException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowTimeoutException(string message, Exception innerException) { throw new TimeoutException(message, innerException); @@ -619,6 +671,7 @@ public static void ThrowTimeoutException(string message, Exception innerExceptio /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowUnauthorizedAccessException(string message) { throw new UnauthorizedAccessException(message); @@ -631,6 +684,7 @@ public static void ThrowUnauthorizedAccessException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowUnauthorizedAccessException(string message, Exception innerException) { throw new UnauthorizedAccessException(message, innerException); @@ -642,6 +696,7 @@ public static void ThrowUnauthorizedAccessException(string message, Exception in /// The Win32 error code associated with this exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowWin32Exception(int error) { throw new Win32Exception(error); @@ -654,6 +709,7 @@ public static void ThrowWin32Exception(int error) /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowWin32Exception(int error, string message) { throw new Win32Exception(error, message); @@ -665,6 +721,7 @@ public static void ThrowWin32Exception(int error, string message) /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowWin32Exception(string message) { throw new Win32Exception(message); @@ -677,6 +734,7 @@ public static void ThrowWin32Exception(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] + [StackTraceHidden] public static void ThrowWin32Exception(string message, Exception innerException) { throw new Win32Exception(message, innerException); diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs index 0ba836dc488..0907a10335e 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; @@ -39,6 +40,7 @@ private static string ToAssertString(this object? obj) /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNull(T value, string name) where T : class { @@ -51,6 +53,7 @@ internal static void ThrowArgumentExceptionForIsNull(T value, string name) /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNull(T? value, string name) where T : struct { @@ -63,6 +66,7 @@ internal static void ThrowArgumentExceptionForIsNull(T? value, string name) /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentNullExceptionForIsNotNull(string name) { ThrowArgumentNullException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be not null)"); @@ -74,6 +78,7 @@ internal static void ThrowArgumentNullExceptionForIsNotNull(string name) /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsOfType(object value, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); @@ -85,6 +90,7 @@ internal static void ThrowArgumentExceptionForIsOfType(object value, string n /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotOfType(object value, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); @@ -95,6 +101,7 @@ internal static void ThrowArgumentExceptionForIsNotOfType(object value, strin /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsOfType(object value, Type type, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); @@ -105,6 +112,7 @@ internal static void ThrowArgumentExceptionForIsOfType(object value, Type type, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotOfType(object value, Type type, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); @@ -116,6 +124,7 @@ internal static void ThrowArgumentExceptionForIsNotOfType(object value, Type typ /// The type being checked against. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsAssignableToType(object value, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); @@ -127,6 +136,7 @@ internal static void ThrowArgumentExceptionForIsAssignableToType(object value /// The type being checked against. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); @@ -137,6 +147,7 @@ internal static void ThrowArgumentExceptionForIsNotAssignableToType(object va /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsAssignableToType(object value, Type type, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); @@ -147,6 +158,7 @@ internal static void ThrowArgumentExceptionForIsAssignableToType(object value, T /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value, Type type, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); @@ -158,6 +170,7 @@ internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value /// The type of input values being compared. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForsBitwiseEqualTo(T value, T target, string name) where T : unmanaged { @@ -170,6 +183,7 @@ internal static void ThrowArgumentExceptionForsBitwiseEqualTo(T value, T targ /// The type of input value being compared. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsReferenceEqualTo(string name) where T : class { @@ -182,6 +196,7 @@ internal static void ThrowArgumentExceptionForIsReferenceEqualTo(string name) /// The type of input value being compared. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsReferenceNotEqualTo(string name) where T : class { @@ -193,6 +208,7 @@ internal static void ThrowArgumentExceptionForIsReferenceNotEqualTo(string na /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsTrue(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false"); @@ -203,6 +219,7 @@ internal static void ThrowArgumentExceptionForIsTrue(string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsTrue(string name, string message) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false: {message.ToAssertString()}"); @@ -213,6 +230,7 @@ internal static void ThrowArgumentExceptionForIsTrue(string name, string message /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsFalse(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true"); @@ -223,6 +241,7 @@ internal static void ThrowArgumentExceptionForIsFalse(string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] + [StackTraceHidden] internal static void ThrowArgumentExceptionForIsFalse(string name, string message) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true: {message.ToAssertString()}"); From ae8ea9022ad9e02eb562999c28dc00a2abc871e9 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 21 Jul 2020 23:06:30 +0200 Subject: [PATCH 14/19] Revert "Added [StackTraceHidden] attribute" This reverts commit f70ae0cdb29055d0cf1637f9c43163af9900524d. Unfortunately the attribute is actually matched by type and not just by name like the others. We should reintroduce this once either https://github.com/dotnet/runtime/issues/29681 is done, or when the runtime switches to a name matching for the internal attribute, so we can just use a local copy here. --- .../Attributes/StackTraceHiddenAttribute.cs | 16 ---- .../Generated/ThrowHelper.Collection.g.cs | 89 ------------------- .../Generated/ThrowHelper.Collection.tt | 12 --- .../ThrowHelper.Collection.Generic.cs | 4 - .../ThrowHelper.Comparable.Generic.cs | 15 ---- .../ThrowHelper.Comparable.Numeric.cs | 9 -- .../Diagnostics/ThrowHelper.IO.cs | 5 -- .../Diagnostics/ThrowHelper.String.cs | 19 ---- .../Diagnostics/ThrowHelper.Tasks.cs | 11 --- .../ThrowHelper.ThrowExceptions.cs | 58 ------------ Microsoft.Toolkit/Diagnostics/ThrowHelper.cs | 19 ---- 11 files changed, 257 deletions(-) delete mode 100644 Microsoft.Toolkit/Attributes/StackTraceHiddenAttribute.cs diff --git a/Microsoft.Toolkit/Attributes/StackTraceHiddenAttribute.cs b/Microsoft.Toolkit/Attributes/StackTraceHiddenAttribute.cs deleted file mode 100644 index c176fb09741..00000000000 --- a/Microsoft.Toolkit/Attributes/StackTraceHiddenAttribute.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -namespace System.Diagnostics -{ - /// - /// Attribute to add to non-returning throw only methods, - /// to restore the stack trace back to what it would be if the throw was in-place - /// - /// Internal copy of the CoreCLR attribute. - [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Struct, Inherited = false)] - internal sealed class StackTraceHiddenAttribute : Attribute - { - } -} \ No newline at end of file diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs index 34d0ea8ed3f..1994b5fcc8c 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs @@ -6,7 +6,6 @@ // ===================== using System; -using System.Diagnostics; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; @@ -26,7 +25,6 @@ public static partial class ThrowHelper /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(Span span, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must be empty, had a size of {span.Length.ToAssertString()}"); @@ -37,7 +35,6 @@ internal static void ThrowArgumentExceptionForIsEmpty(Span span, string na /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size equal to {size}, had a size of {span.Length.ToAssertString()}"); @@ -48,7 +45,6 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(Span span, in /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size not equal to {size}, had a size of {span.Length.ToAssertString()}"); @@ -59,7 +55,6 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(Span span, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}"); @@ -70,7 +65,6 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(Span span /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}"); @@ -81,7 +75,6 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Spa /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size less than {size}, had a size of {span.Length.ToAssertString()}"); @@ -92,7 +85,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(Span span, i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size less than or equal to {size}, had a size of {span.Length.ToAssertString()}"); @@ -103,7 +95,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(Span source, Span destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -114,7 +105,6 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(Span source, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span source, Span destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -125,7 +115,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Span [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Span span, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {span.Length.ToAssertString()} to be a valid index for the target collection ({typeof(Span).ToTypeString()}), was {index.ToAssertString()}"); @@ -136,7 +125,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Span span, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {span.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(Span).ToTypeString()}), was {index.ToAssertString()}"); @@ -147,7 +135,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(ReadOnlySpan span, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must be empty, had a size of {span.Length.ToAssertString()}"); @@ -158,7 +145,6 @@ internal static void ThrowArgumentExceptionForIsEmpty(ReadOnlySpan span, s /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size equal to {size}, had a size of {span.Length.ToAssertString()}"); @@ -169,7 +155,6 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size not equal to {size}, had a size of {span.Length.ToAssertString()}"); @@ -180,7 +165,6 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlySpan< /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}"); @@ -191,7 +175,6 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlySpan /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}"); @@ -202,7 +185,6 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Rea /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than {size}, had a size of {span.Length.ToAssertString()}"); @@ -213,7 +195,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlySpan /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlySpan span, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than or equal to {size}, had a size of {span.Length.ToAssertString()}"); @@ -224,7 +205,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOn /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan source, Span destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -235,7 +215,6 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlySpan /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlySpan source, Span destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -246,7 +225,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOn /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlySpan span, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {span.Length.ToAssertString()} to be a valid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {index.ToAssertString()}"); @@ -257,7 +235,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlySpan span, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {span.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(ReadOnlySpan).ToTypeString()}), was {index.ToAssertString()}"); @@ -268,7 +245,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(Memory memory, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must be empty, had a size of {memory.Length.ToAssertString()}"); @@ -279,7 +255,6 @@ internal static void ThrowArgumentExceptionForIsEmpty(Memory memory, strin /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size equal to {size}, had a size of {memory.Length.ToAssertString()}"); @@ -290,7 +265,6 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(Memory memory /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size not equal to {size}, had a size of {memory.Length.ToAssertString()}"); @@ -301,7 +275,6 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(Memory mem /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}"); @@ -312,7 +285,6 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(Memory me /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}"); @@ -323,7 +295,6 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Mem /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size less than {size}, had a size of {memory.Length.ToAssertString()}"); @@ -334,7 +305,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(Memory memor /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size less than or equal to {size}, had a size of {memory.Length.ToAssertString()}"); @@ -345,7 +315,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(Memory source, Memory destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -356,7 +325,6 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(Memory source /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory source, Memory destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -367,7 +335,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(Memory /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, Memory memory, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {memory.Length.ToAssertString()} to be a valid index for the target collection ({typeof(Memory).ToTypeString()}), was {index.ToAssertString()}"); @@ -378,7 +345,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, Memory memory, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {memory.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(Memory).ToTypeString()}), was {index.ToAssertString()}"); @@ -389,7 +355,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(ReadOnlyMemory memory, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must be empty, had a size of {memory.Length.ToAssertString()}"); @@ -400,7 +365,6 @@ internal static void ThrowArgumentExceptionForIsEmpty(ReadOnlyMemory memor /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size equal to {size}, had a size of {memory.Length.ToAssertString()}"); @@ -411,7 +375,6 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size not equal to {size}, had a size of {memory.Length.ToAssertString()}"); @@ -422,7 +385,6 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlyMemor /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}"); @@ -433,7 +395,6 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlyMemo /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}"); @@ -444,7 +405,6 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Rea /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than {size}, had a size of {memory.Length.ToAssertString()}"); @@ -455,7 +415,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(ReadOnlyMemory< /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlyMemory memory, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than or equal to {size}, had a size of {memory.Length.ToAssertString()}"); @@ -466,7 +425,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOn /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory source, Memory destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -477,7 +435,6 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(ReadOnlyMemory [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOnlyMemory source, Memory destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -488,7 +445,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ReadOn /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ReadOnlyMemory memory, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {memory.Length.ToAssertString()} to be a valid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {index.ToAssertString()}"); @@ -499,7 +455,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ReadOnlyMemory memory, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {memory.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(ReadOnlyMemory).ToTypeString()}), was {index.ToAssertString()}"); @@ -510,7 +465,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(T[] array, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must be empty, had a size of {array.Length.ToAssertString()}"); @@ -521,7 +475,6 @@ internal static void ThrowArgumentExceptionForIsEmpty(T[] array, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size equal to {size}, had a size of {array.Length.ToAssertString()}"); @@ -532,7 +485,6 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(T[] array, int s /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size not equal to {size}, had a size of {array.Length.ToAssertString()}"); @@ -543,7 +495,6 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(T[] array, in /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size over {size}, had a size of {array.Length.ToAssertString()}"); @@ -554,7 +505,6 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(T[] array, i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size of at least {size}, had a size of {array.Length.ToAssertString()}"); @@ -565,7 +515,6 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(T[] /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size less than {size}, had a size of {array.Length.ToAssertString()}"); @@ -576,7 +525,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(T[] array, int /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] array, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size less than or equal to {size}, had a size of {array.Length.ToAssertString()}"); @@ -587,7 +535,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] ar /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(T[] source, T[] destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -598,7 +545,6 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(T[] source, T[] /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] source, T[] destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -609,7 +555,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(T[] so /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, T[] array, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {array.Length.ToAssertString()} to be a valid index for the target collection ({typeof(T[]).ToTypeString()}), was {index.ToAssertString()}"); @@ -620,7 +565,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, T[] array, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {array.Length.ToAssertString()} to be an invalid index for the target collection ({typeof(T[]).ToTypeString()}), was {index.ToAssertString()}"); @@ -631,7 +575,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(List list, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must be empty, had a size of {list.Count.ToAssertString()}"); @@ -642,7 +585,6 @@ internal static void ThrowArgumentExceptionForIsEmpty(List list, string na /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size equal to {size}, had a size of {list.Count.ToAssertString()}"); @@ -653,7 +595,6 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(List list, in /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size not equal to {size}, had a size of {list.Count.ToAssertString()}"); @@ -664,7 +605,6 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(List list, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size over {size}, had a size of {list.Count.ToAssertString()}"); @@ -675,7 +615,6 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(List list /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size of at least {size}, had a size of {list.Count.ToAssertString()}"); @@ -686,7 +625,6 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Lis /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size less than {size}, had a size of {list.Count.ToAssertString()}"); @@ -697,7 +635,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(List list, i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List list, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size less than or equal to {size}, had a size of {list.Count.ToAssertString()}"); @@ -708,7 +645,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(List source, List destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); @@ -719,7 +655,6 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(List source, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List source, List destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size less than or equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); @@ -730,7 +665,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(List [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, List list, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {list.Count.ToAssertString()} to be a valid index for the target collection ({typeof(List).ToTypeString()}), was {index.ToAssertString()}"); @@ -741,7 +675,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, List list, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {list.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(List).ToTypeString()}), was {index.ToAssertString()}"); @@ -752,7 +685,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(ICollection collection, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must be empty, had a size of {collection.Count.ToAssertString()}"); @@ -763,7 +695,6 @@ internal static void ThrowArgumentExceptionForIsEmpty(ICollection collecti /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size equal to {size}, had a size of {collection.Count.ToAssertString()}"); @@ -774,7 +705,6 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection c /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size not equal to {size}, had a size of {collection.Count.ToAssertString()}"); @@ -785,7 +715,6 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(ICollection [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}"); @@ -796,7 +725,6 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(ICollection< /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}"); @@ -807,7 +735,6 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ICo /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size less than {size}, had a size of {collection.Count.ToAssertString()}"); @@ -818,7 +745,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(ICollection /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size less than or equal to {size}, had a size of {collection.Count.ToAssertString()}"); @@ -829,7 +755,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IColle /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection source, ICollection destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); @@ -840,7 +765,6 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(ICollection s /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(ICollection source, ICollection destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size less than or equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); @@ -851,7 +775,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IColle /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, ICollection collection, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {collection.Count.ToAssertString()} to be a valid index for the target collection ({typeof(ICollection).ToTypeString()}), was {index.ToAssertString()}"); @@ -862,7 +785,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, ICollection collection, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {collection.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(ICollection).ToTypeString()}), was {index.ToAssertString()}"); @@ -873,7 +795,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int i /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(IReadOnlyCollection collection, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must be empty, had a size of {collection.Count.ToAssertString()}"); @@ -884,7 +805,6 @@ internal static void ThrowArgumentExceptionForIsEmpty(IReadOnlyCollection /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size equal to {size}, had a size of {collection.Count.ToAssertString()}"); @@ -895,7 +815,6 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollect /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size not equal to {size}, had a size of {collection.Count.ToAssertString()}"); @@ -906,7 +825,6 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(IReadOnlyColl /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}"); @@ -917,7 +835,6 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(IReadOnlyCol /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}"); @@ -928,7 +845,6 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(IRe /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than {size}, had a size of {collection.Count.ToAssertString()}"); @@ -939,7 +855,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(IReadOnlyCollec /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnlyCollection collection, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than or equal to {size}, had a size of {collection.Count.ToAssertString()}"); @@ -950,7 +865,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadO /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollection source, ICollection destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); @@ -961,7 +875,6 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(IReadOnlyCollect /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadOnlyCollection source, ICollection destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size less than or equal to {destination.Count.ToAssertString()} (the destination), had a size of {source.Count.ToAssertString()}"); @@ -972,7 +885,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(IReadO /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, IReadOnlyCollection collection, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {collection.Count.ToAssertString()} to be a valid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {index.ToAssertString()}"); @@ -983,7 +895,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int inde /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, IReadOnlyCollection collection, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {collection.Count.ToAssertString()} to be an invalid index for the target collection ({typeof(IReadOnlyCollection).ToTypeString()}), was {index.ToAssertString()}"); diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt index 99c138d35be..731065134fc 100644 --- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt +++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. <#@include file="TypeInfo.ttinclude" #> using System; -using System.Diagnostics; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; @@ -27,7 +26,6 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(<#=item.Type#> <#=item.Name#>, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must be empty, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); @@ -38,7 +36,6 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); @@ -49,7 +46,6 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size not equal to {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); @@ -60,7 +56,6 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size over {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); @@ -71,7 +66,6 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size of at least {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); @@ -82,7 +76,6 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); @@ -93,7 +86,6 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}"); @@ -104,7 +96,6 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size equal to {destination.<#=item.Size#>.ToAssertString()} (the destination), had a size of {source.<#=item.Size#>.ToAssertString()}"); @@ -115,7 +106,6 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size less than or equal to {destination.<#=item.Size#>.ToAssertString()} (the destination), had a size of {source.<#=item.Size#>.ToAssertString()}"); @@ -126,7 +116,6 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {<#=item.Name#>.<#=item.Size#>.ToAssertString()} to be a valid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {index.ToAssertString()}"); @@ -137,7 +126,6 @@ GenerateTextForItems(EnumerableTypes, item => /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, <#=item.Type#> <#=item.Name#>, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {<#=item.Name#>.<#=item.Size#>.ToAssertString()} to be an invalid index for the target collection ({typeof(<#=item.Type#>).ToTypeString()}), was {index.ToAssertString()}"); diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs index 5e0df16cc5f..9ef29cbd440 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; @@ -24,7 +23,6 @@ public static partial class ThrowHelper /// This method is needed because can't be used as a generic type parameter. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must not be empty"); @@ -37,7 +35,6 @@ internal static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) /// This method is needed because can't be used as a generic type parameter. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must not be empty"); @@ -49,7 +46,6 @@ internal static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(stri /// The item of items in the input collection. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotEmpty(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be empty"); diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs index 23d86f9319b..030ede72c30 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; @@ -23,7 +22,6 @@ public static partial class ThrowHelper /// The type of value type being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsDefault(T value, string name) where T : struct { @@ -36,7 +34,6 @@ internal static void ThrowArgumentExceptionForIsDefault(T value, string name) /// The type of value type being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotDefault(string name) where T : struct { @@ -49,7 +46,6 @@ internal static void ThrowArgumentExceptionForIsNotDefault(string name) /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEqualTo(T value, T target, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be equal to {target.ToAssertString()}, was {value.ToAssertString()}"); @@ -61,7 +57,6 @@ internal static void ThrowArgumentExceptionForIsEqualTo(T value, T target, st /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be equal to {target.ToAssertString()}, was {value.ToAssertString()}"); @@ -73,7 +68,6 @@ internal static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T maximum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than {maximum.ToAssertString()}, was {value.ToAssertString()}"); @@ -85,7 +79,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T value, T maximum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than or equal to {maximum.ToAssertString()}, was {value.ToAssertString()}"); @@ -97,7 +90,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value, T minimum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than {minimum.ToAssertString()}, was {value.ToAssertString()}"); @@ -109,7 +101,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(T value, T minimum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than or equal to {minimum.ToAssertString()}, was {value.ToAssertString()}"); @@ -121,7 +112,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualToThe type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); @@ -133,7 +123,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be in the range given by {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); @@ -145,7 +134,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); @@ -157,7 +145,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); @@ -169,7 +156,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); @@ -181,7 +167,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T /// The type of values being tested. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo(T value, T minimum, T maximum, string name) { ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be between or equal to {minimum.ToAssertString()} and {maximum.ToAssertString()}, was {value.ToAssertString()}"); diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs index d3286382b1e..f249e812dc4 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Microsoft.Toolkit.Extensions; @@ -22,7 +21,6 @@ public static partial class ThrowHelper /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsCloseTo(int value, int target, uint delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(int).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((double)((long)value - target)).ToAssertString()}"); @@ -33,7 +31,6 @@ internal static void ThrowArgumentExceptionForIsCloseTo(int value, int target, u /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotCloseTo(int value, int target, uint delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(int).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((double)((long)value - target)).ToAssertString()}"); @@ -44,7 +41,6 @@ internal static void ThrowArgumentExceptionForIsNotCloseTo(int value, int target /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsCloseTo(long value, long target, ulong delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(long).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((decimal)value - target).ToAssertString()}"); @@ -55,7 +51,6 @@ internal static void ThrowArgumentExceptionForIsCloseTo(long value, long target, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotCloseTo(long value, long target, ulong delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(long).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs((decimal)value - target).ToAssertString()}"); @@ -66,7 +61,6 @@ internal static void ThrowArgumentExceptionForIsNotCloseTo(long value, long targ /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsCloseTo(float value, float target, float delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(float).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); @@ -77,7 +71,6 @@ internal static void ThrowArgumentExceptionForIsCloseTo(float value, float targe /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotCloseTo(float value, float target, float delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(float).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); @@ -88,7 +81,6 @@ internal static void ThrowArgumentExceptionForIsNotCloseTo(float value, float ta /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsCloseTo(double value, double target, double delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(double).ToTypeString()}) must be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); @@ -99,7 +91,6 @@ internal static void ThrowArgumentExceptionForIsCloseTo(double value, double tar /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotCloseTo(double value, double target, double delta, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(double).ToTypeString()}) must not be within a distance of {delta.ToAssertString()} from {target.ToAssertString()}, was {value.ToAssertString()} and had a distance of {Math.Abs(value - target).ToAssertString()}"); diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs index 8e0655ed217..442ea37c063 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Runtime.CompilerServices; @@ -23,7 +22,6 @@ public static partial class ThrowHelper /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForCanRead(Stream stream, string name) { ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support reading"); @@ -34,7 +32,6 @@ internal static void ThrowArgumentExceptionForCanRead(Stream stream, string name /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForCanWrite(Stream stream, string name) { ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support writing"); @@ -45,7 +42,6 @@ internal static void ThrowArgumentExceptionForCanWrite(Stream stream, string nam /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForCanSeek(Stream stream, string name) { ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) doesn't support seeking"); @@ -56,7 +52,6 @@ internal static void ThrowArgumentExceptionForCanSeek(Stream stream, string name /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsAtStartPosition(Stream stream, string name) { ThrowArgumentException(name, $"Stream {name.ToAssertString()} ({stream.GetType().ToTypeString()}) must be at position {0.ToAssertString()}, was at {stream.Position.ToAssertString()}"); diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs index 24d48bfeb36..bfcbed6f835 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; @@ -21,7 +20,6 @@ public static partial class ThrowHelper /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNullOrEmpty(string? text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be null or empty, was {text.ToAssertString()}"); @@ -32,7 +30,6 @@ internal static void ThrowArgumentExceptionForIsNullOrEmpty(string? text, string /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotNullOrEmpty(string? text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be null or empty, was {(text is null ? "null" : "empty")}"); @@ -43,7 +40,6 @@ internal static void ThrowArgumentExceptionForIsNotNullOrEmpty(string? text, str /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNullOrWhitespace(string? text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be null or whitespace, was {text.ToAssertString()}"); @@ -54,7 +50,6 @@ internal static void ThrowArgumentExceptionForIsNullOrWhitespace(string? text, s /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotNullOrWhitespace(string? text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be null or whitespace, was {(text is null ? "null" : "whitespace")}"); @@ -65,7 +60,6 @@ internal static void ThrowArgumentExceptionForIsNotNullOrWhitespace(string? text /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsEmpty(string text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be empty, was {text.ToAssertString()}"); @@ -76,7 +70,6 @@ internal static void ThrowArgumentExceptionForIsEmpty(string text, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotEmpty(string text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be empty"); @@ -87,7 +80,6 @@ internal static void ThrowArgumentExceptionForIsNotEmpty(string text, string nam /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsWhitespace(string text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must be whitespace, was {text.ToAssertString()}"); @@ -98,7 +90,6 @@ internal static void ThrowArgumentExceptionForIsWhitespace(string text, string n /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotWhitespace(string text, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not be whitespace, was {text.ToAssertString()}"); @@ -109,7 +100,6 @@ internal static void ThrowArgumentExceptionForIsNotWhitespace(string text, strin /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size equal to {size}, had a size of {text.Length} and was {text.ToAssertString()}"); @@ -120,7 +110,6 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int si /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must not have a size equal to {size}, was {text.ToAssertString()}"); @@ -131,7 +120,6 @@ internal static void ThrowArgumentExceptionForHasSizeNotEqualTo(string text, int /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThan(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size over {size}, had a size of {text.Length} and was {text.ToAssertString()}"); @@ -142,7 +130,6 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThan(string text, in /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size of at least {size}, had a size of {text.Length} and was {text.ToAssertString()}"); @@ -153,7 +140,6 @@ internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(string /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThan(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size less than {size}, had a size of {text.Length} and was {text.ToAssertString()}"); @@ -164,7 +150,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThan(string text, int s /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string text, int size, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} (string) must have a size less than or equal to {size}, had a size of {text.Length} and was {text.ToAssertString()}"); @@ -175,7 +160,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string te /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeEqualTo(string source, string destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} (string) must have a size equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -186,7 +170,6 @@ internal static void ThrowArgumentExceptionForHasSizeEqualTo(string source, stri /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string source, string destination, string name) { ThrowArgumentException(name, $"The source {name.ToAssertString()} (string) must have a size less than or equal to {destination.Length.ToAssertString()} (the destination), had a size of {source.Length.ToAssertString()}"); @@ -197,7 +180,6 @@ internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(string so /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, string text, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must be in the range given by <0> and {text.Length.ToAssertString()} to be a valid index for the target string, was {index.ToAssertString()}"); @@ -208,7 +190,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor(int index, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(int index, string text, string name) { ThrowArgumentOutOfRangeException(name, index, $"Parameter {name.ToAssertString()} (int) must not be in the range given by <0> and {text.Length.ToAssertString()} to be an invalid index for the target string, was {index.ToAssertString()}"); diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs index 69ee19403db..09f8db9c14b 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Threading.Tasks; @@ -23,7 +22,6 @@ public static partial class ThrowHelper /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsCompleted(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be completed, had status {task.Status.ToAssertString()}"); @@ -34,7 +32,6 @@ internal static void ThrowArgumentExceptionForIsCompleted(Task task, string name /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotCompleted(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be completed, had status {task.Status.ToAssertString()}"); @@ -45,7 +42,6 @@ internal static void ThrowArgumentExceptionForIsNotCompleted(Task task, string n /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsCompletedSuccessfully(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be completed successfully, had status {task.Status.ToAssertString()}"); @@ -56,7 +52,6 @@ internal static void ThrowArgumentExceptionForIsCompletedSuccessfully(Task task, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotCompletedSuccessfully(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be completed successfully, had status {task.Status.ToAssertString()}"); @@ -67,7 +62,6 @@ internal static void ThrowArgumentExceptionForIsNotCompletedSuccessfully(Task ta /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsFaulted(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be faulted, had status {task.Status.ToAssertString()}"); @@ -78,7 +72,6 @@ internal static void ThrowArgumentExceptionForIsFaulted(Task task, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotFaulted(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be faulted, had status {task.Status.ToAssertString()}"); @@ -89,7 +82,6 @@ internal static void ThrowArgumentExceptionForIsNotFaulted(Task task, string nam /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsCanceled(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must be canceled, had status {task.Status.ToAssertString()}"); @@ -100,7 +92,6 @@ internal static void ThrowArgumentExceptionForIsCanceled(Task task, string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotCanceled(Task task, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not be canceled, had status {task.Status.ToAssertString()}"); @@ -111,7 +102,6 @@ internal static void ThrowArgumentExceptionForIsNotCanceled(Task task, string na /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasStatusEqualTo(Task task, TaskStatus status, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must have status {status}, had status {task.Status.ToAssertString()}"); @@ -122,7 +112,6 @@ internal static void ThrowArgumentExceptionForHasStatusEqualTo(Task task, TaskSt /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForHasStatusNotEqualTo(Task task, TaskStatus status, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({task.GetType().ToTypeString()}) must not have status {status.ToAssertString()}"); diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs index 2b03427f10e..103c3ef12ad 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs @@ -4,7 +4,6 @@ using System; using System.ComponentModel; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Runtime.InteropServices; @@ -25,7 +24,6 @@ public static partial class ThrowHelper /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowArrayTypeMismatchException(string message) { throw new ArrayTypeMismatchException(message); @@ -38,7 +36,6 @@ public static void ThrowArrayTypeMismatchException(string message) /// The inner to include. /// Thrown with the specified parameters. [DoesNotReturn] - [StackTraceHidden] public static void ThrowArrayTypeMismatchException(string message, Exception innerException) { throw new ArrayTypeMismatchException(message, innerException); @@ -50,7 +47,6 @@ public static void ThrowArrayTypeMismatchException(string message, Exception inn /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowArgumentException(string message) { throw new ArgumentException(message); @@ -63,7 +59,6 @@ public static void ThrowArgumentException(string message) /// The inner to include. /// Thrown with the specified parameters. [DoesNotReturn] - [StackTraceHidden] public static void ThrowArgumentException(string message, Exception innerException) { throw new ArgumentException(message, innerException); @@ -76,7 +71,6 @@ public static void ThrowArgumentException(string message, Exception innerExcepti /// The message to include in the exception. /// Thrown with the specified parameters. [DoesNotReturn] - [StackTraceHidden] public static void ThrowArgumentException(string name, string message) { throw new ArgumentException(message, name); @@ -90,7 +84,6 @@ public static void ThrowArgumentException(string name, string message) /// The inner to include. /// Thrown with the specified parameters. [DoesNotReturn] - [StackTraceHidden] public static void ThrowArgumentException(string name, string message, Exception innerException) { throw new ArgumentException(message, name, innerException); @@ -102,7 +95,6 @@ public static void ThrowArgumentException(string name, string message, Exception /// The argument name. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowArgumentNullException(string name) { throw new ArgumentNullException(name); @@ -115,7 +107,6 @@ public static void ThrowArgumentNullException(string name) /// The inner to include. /// Thrown with the specified parameters. [DoesNotReturn] - [StackTraceHidden] public static void ThrowArgumentNullException(string name, Exception innerException) { throw new ArgumentNullException(name, innerException); @@ -128,7 +119,6 @@ public static void ThrowArgumentNullException(string name, Exception innerExcept /// The message to include in the exception. /// Thrown with the specified parameters. [DoesNotReturn] - [StackTraceHidden] public static void ThrowArgumentNullException(string name, string message) { throw new ArgumentNullException(name, message); @@ -140,7 +130,6 @@ public static void ThrowArgumentNullException(string name, string message) /// The argument name. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowArgumentOutOfRangeException(string name) { throw new ArgumentOutOfRangeException(name); @@ -153,7 +142,6 @@ public static void ThrowArgumentOutOfRangeException(string name) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowArgumentOutOfRangeException(string name, Exception innerException) { throw new ArgumentOutOfRangeException(name, innerException); @@ -166,7 +154,6 @@ public static void ThrowArgumentOutOfRangeException(string name, Exception inner /// The message to include in the exception. /// Thrown with the specified parameters. [DoesNotReturn] - [StackTraceHidden] public static void ThrowArgumentOutOfRangeException(string name, string message) { throw new ArgumentOutOfRangeException(name, message); @@ -180,7 +167,6 @@ public static void ThrowArgumentOutOfRangeException(string name, string message) /// The message to include in the exception. /// Thrown with the specified parameters. [DoesNotReturn] - [StackTraceHidden] public static void ThrowArgumentOutOfRangeException(string name, object value, string message) { throw new ArgumentOutOfRangeException(name, value, message); @@ -192,7 +178,6 @@ public static void ThrowArgumentOutOfRangeException(string name, object value, s /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowExternalException(string message) { throw new ExternalException(message); @@ -205,7 +190,6 @@ public static void ThrowExternalException(string message) /// The inner to include. /// Thrown with the specified parameters. [DoesNotReturn] - [StackTraceHidden] public static void ThrowExternalException(string message, Exception innerException) { throw new ExternalException(message, innerException); @@ -218,7 +202,6 @@ public static void ThrowExternalException(string message, Exception innerExcepti /// The HRESULT of the errror to include. /// Thrown with the specified parameters. [DoesNotReturn] - [StackTraceHidden] public static void ThrowExternalException(string message, int error) { throw new ExternalException(message, error); @@ -230,7 +213,6 @@ public static void ThrowExternalException(string message, int error) /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowFormatException(string message) { throw new FormatException(message); @@ -243,7 +225,6 @@ public static void ThrowFormatException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowFormatException(string message, Exception innerException) { throw new FormatException(message, innerException); @@ -255,7 +236,6 @@ public static void ThrowFormatException(string message, Exception innerException /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowInsufficientMemoryException(string message) { throw new InsufficientMemoryException(message); @@ -268,7 +248,6 @@ public static void ThrowInsufficientMemoryException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowInsufficientMemoryException(string message, Exception innerException) { throw new InsufficientMemoryException(message, innerException); @@ -280,7 +259,6 @@ public static void ThrowInsufficientMemoryException(string message, Exception in /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowInvalidDataException(string message) { throw new InvalidDataException(message); @@ -293,7 +271,6 @@ public static void ThrowInvalidDataException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowInvalidDataException(string message, Exception innerException) { throw new InvalidDataException(message, innerException); @@ -305,7 +282,6 @@ public static void ThrowInvalidDataException(string message, Exception innerExce /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowInvalidOperationException(string message) { throw new InvalidOperationException(message); @@ -318,7 +294,6 @@ public static void ThrowInvalidOperationException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowInvalidOperationException(string message, Exception innerException) { throw new InvalidOperationException(message, innerException); @@ -330,7 +305,6 @@ public static void ThrowInvalidOperationException(string message, Exception inne /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowLockRecursionException(string message) { throw new LockRecursionException(message); @@ -343,7 +317,6 @@ public static void ThrowLockRecursionException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowLockRecursionException(string message, Exception innerException) { throw new LockRecursionException(message, innerException); @@ -355,7 +328,6 @@ public static void ThrowLockRecursionException(string message, Exception innerEx /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowMissingFieldException(string message) { throw new MissingFieldException(message); @@ -368,7 +340,6 @@ public static void ThrowMissingFieldException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowMissingFieldException(string message, Exception innerException) { throw new MissingFieldException(message, innerException); @@ -381,7 +352,6 @@ public static void ThrowMissingFieldException(string message, Exception innerExc /// The target field being retrieved. /// Thrown with the specified parameters. [DoesNotReturn] - [StackTraceHidden] public static void ThrowMissingFieldException(string className, string fieldName) { throw new MissingFieldException(className, fieldName); @@ -393,7 +363,6 @@ public static void ThrowMissingFieldException(string className, string fieldName /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowMissingMemberException(string message) { throw new MissingMemberException(message); @@ -406,7 +375,6 @@ public static void ThrowMissingMemberException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowMissingMemberException(string message, Exception innerException) { throw new MissingMemberException(message, innerException); @@ -419,7 +387,6 @@ public static void ThrowMissingMemberException(string message, Exception innerEx /// The target member being retrieved. /// Thrown with the specified parameters. [DoesNotReturn] - [StackTraceHidden] public static void ThrowMissingMemberException(string className, string memberName) { throw new MissingMemberException(className, memberName); @@ -431,7 +398,6 @@ public static void ThrowMissingMemberException(string className, string memberNa /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowMissingMethodException(string message) { throw new MissingMethodException(message); @@ -444,7 +410,6 @@ public static void ThrowMissingMethodException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowMissingMethodException(string message, Exception innerException) { throw new MissingMethodException(message, innerException); @@ -457,7 +422,6 @@ public static void ThrowMissingMethodException(string message, Exception innerEx /// The target method being retrieved. /// Thrown with the specified parameters. [DoesNotReturn] - [StackTraceHidden] public static void ThrowMissingMethodException(string className, string methodName) { throw new MissingMethodException(className, methodName); @@ -469,7 +433,6 @@ public static void ThrowMissingMethodException(string className, string methodNa /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowNotSupportedException(string message) { throw new NotSupportedException(message); @@ -482,7 +445,6 @@ public static void ThrowNotSupportedException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowNotSupportedException(string message, Exception innerException) { throw new NotSupportedException(message, innerException); @@ -494,7 +456,6 @@ public static void ThrowNotSupportedException(string message, Exception innerExc /// The name of the disposed object. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowObjectDisposedException(string objectName) { throw new ObjectDisposedException(objectName); @@ -507,7 +468,6 @@ public static void ThrowObjectDisposedException(string objectName) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowObjectDisposedException(string objectName, Exception innerException) { throw new ObjectDisposedException(objectName, innerException); @@ -520,7 +480,6 @@ public static void ThrowObjectDisposedException(string objectName, Exception inn /// The message to include in the exception. /// Thrown with the specified parameters. [DoesNotReturn] - [StackTraceHidden] public static void ThrowObjectDisposedException(string objectName, string message) { throw new ObjectDisposedException(objectName, message); @@ -532,7 +491,6 @@ public static void ThrowObjectDisposedException(string objectName, string messag /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowOperationCanceledException(string message) { throw new OperationCanceledException(message); @@ -545,7 +503,6 @@ public static void ThrowOperationCanceledException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowOperationCanceledException(string message, Exception innerException) { throw new OperationCanceledException(message, innerException); @@ -557,7 +514,6 @@ public static void ThrowOperationCanceledException(string message, Exception inn /// The in use. /// Thrown with the specified parameters. [DoesNotReturn] - [StackTraceHidden] public static void ThrowOperationCanceledException(CancellationToken token) { throw new OperationCanceledException(token); @@ -570,7 +526,6 @@ public static void ThrowOperationCanceledException(CancellationToken token) /// The in use. /// Thrown with the specified parameters. [DoesNotReturn] - [StackTraceHidden] public static void ThrowOperationCanceledException(string message, CancellationToken token) { throw new OperationCanceledException(message, token); @@ -584,7 +539,6 @@ public static void ThrowOperationCanceledException(string message, CancellationT /// The in use. /// Thrown with the specified parameters. [DoesNotReturn] - [StackTraceHidden] public static void ThrowOperationCanceledException(string message, Exception innerException, CancellationToken token) { throw new OperationCanceledException(message, innerException, token); @@ -596,7 +550,6 @@ public static void ThrowOperationCanceledException(string message, Exception inn /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowPlatformNotSupportedException(string message) { throw new PlatformNotSupportedException(message); @@ -609,7 +562,6 @@ public static void ThrowPlatformNotSupportedException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowPlatformNotSupportedException(string message, Exception innerException) { throw new PlatformNotSupportedException(message, innerException); @@ -621,7 +573,6 @@ public static void ThrowPlatformNotSupportedException(string message, Exception /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowSynchronizationLockException(string message) { throw new SynchronizationLockException(message); @@ -634,7 +585,6 @@ public static void ThrowSynchronizationLockException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowSynchronizationLockException(string message, Exception innerException) { throw new SynchronizationLockException(message, innerException); @@ -646,7 +596,6 @@ public static void ThrowSynchronizationLockException(string message, Exception i /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowTimeoutException(string message) { throw new TimeoutException(message); @@ -659,7 +608,6 @@ public static void ThrowTimeoutException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowTimeoutException(string message, Exception innerException) { throw new TimeoutException(message, innerException); @@ -671,7 +619,6 @@ public static void ThrowTimeoutException(string message, Exception innerExceptio /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowUnauthorizedAccessException(string message) { throw new UnauthorizedAccessException(message); @@ -684,7 +631,6 @@ public static void ThrowUnauthorizedAccessException(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowUnauthorizedAccessException(string message, Exception innerException) { throw new UnauthorizedAccessException(message, innerException); @@ -696,7 +642,6 @@ public static void ThrowUnauthorizedAccessException(string message, Exception in /// The Win32 error code associated with this exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowWin32Exception(int error) { throw new Win32Exception(error); @@ -709,7 +654,6 @@ public static void ThrowWin32Exception(int error) /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowWin32Exception(int error, string message) { throw new Win32Exception(error, message); @@ -721,7 +665,6 @@ public static void ThrowWin32Exception(int error, string message) /// The message to include in the exception. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowWin32Exception(string message) { throw new Win32Exception(message); @@ -734,7 +677,6 @@ public static void ThrowWin32Exception(string message) /// The inner to include. /// Thrown with the specified parameter. [DoesNotReturn] - [StackTraceHidden] public static void ThrowWin32Exception(string message, Exception innerException) { throw new Win32Exception(message, innerException); diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs index 0907a10335e..0ba836dc488 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; @@ -40,7 +39,6 @@ private static string ToAssertString(this object? obj) /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNull(T value, string name) where T : class { @@ -53,7 +51,6 @@ internal static void ThrowArgumentExceptionForIsNull(T value, string name) /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNull(T? value, string name) where T : struct { @@ -66,7 +63,6 @@ internal static void ThrowArgumentExceptionForIsNull(T? value, string name) /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentNullExceptionForIsNotNull(string name) { ThrowArgumentNullException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be not null)"); @@ -78,7 +74,6 @@ internal static void ThrowArgumentNullExceptionForIsNotNull(string name) /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsOfType(object value, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); @@ -90,7 +85,6 @@ internal static void ThrowArgumentExceptionForIsOfType(object value, string n /// The type of the input value. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotOfType(object value, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); @@ -101,7 +95,6 @@ internal static void ThrowArgumentExceptionForIsNotOfType(object value, strin /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsOfType(object value, Type type, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); @@ -112,7 +105,6 @@ internal static void ThrowArgumentExceptionForIsOfType(object value, Type type, /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotOfType(object value, Type type, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); @@ -124,7 +116,6 @@ internal static void ThrowArgumentExceptionForIsNotOfType(object value, Type typ /// The type being checked against. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsAssignableToType(object value, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); @@ -136,7 +127,6 @@ internal static void ThrowArgumentExceptionForIsAssignableToType(object value /// The type being checked against. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); @@ -147,7 +137,6 @@ internal static void ThrowArgumentExceptionForIsNotAssignableToType(object va /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsAssignableToType(object value, Type type, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); @@ -158,7 +147,6 @@ internal static void ThrowArgumentExceptionForIsAssignableToType(object value, T /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value, Type type, string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); @@ -170,7 +158,6 @@ internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value /// The type of input values being compared. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForsBitwiseEqualTo(T value, T target, string name) where T : unmanaged { @@ -183,7 +170,6 @@ internal static void ThrowArgumentExceptionForsBitwiseEqualTo(T value, T targ /// The type of input value being compared. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsReferenceEqualTo(string name) where T : class { @@ -196,7 +182,6 @@ internal static void ThrowArgumentExceptionForIsReferenceEqualTo(string name) /// The type of input value being compared. [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsReferenceNotEqualTo(string name) where T : class { @@ -208,7 +193,6 @@ internal static void ThrowArgumentExceptionForIsReferenceNotEqualTo(string na /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsTrue(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false"); @@ -219,7 +203,6 @@ internal static void ThrowArgumentExceptionForIsTrue(string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsTrue(string name, string message) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false: {message.ToAssertString()}"); @@ -230,7 +213,6 @@ internal static void ThrowArgumentExceptionForIsTrue(string name, string message /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsFalse(string name) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true"); @@ -241,7 +223,6 @@ internal static void ThrowArgumentExceptionForIsFalse(string name) /// [MethodImpl(MethodImplOptions.NoInlining)] [DoesNotReturn] - [StackTraceHidden] internal static void ThrowArgumentExceptionForIsFalse(string name, string message) { ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true: {message.ToAssertString()}"); From 418c2461ddf68f3101385143677e37cb29926482 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 22 Jul 2020 00:07:02 +0200 Subject: [PATCH 15/19] Added unit tests for new ThrowHelper APIs --- .../Diagnostics/Test_ThrowHelper.cs | 82 +++++++++++++++++++ .../UnitTests.Shared.projitems | 1 + 2 files changed, 83 insertions(+) create mode 100644 UnitTests/UnitTests.Shared/Diagnostics/Test_ThrowHelper.cs diff --git a/UnitTests/UnitTests.Shared/Diagnostics/Test_ThrowHelper.cs b/UnitTests/UnitTests.Shared/Diagnostics/Test_ThrowHelper.cs new file mode 100644 index 00000000000..c9ac6ec63cc --- /dev/null +++ b/UnitTests/UnitTests.Shared/Diagnostics/Test_ThrowHelper.cs @@ -0,0 +1,82 @@ +// 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.Linq; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Threading; +using Microsoft.Toolkit.Diagnostics; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace UnitTests.Diagnostics +{ + [TestClass] + public class Test_ThrowHelper + { + /// + /// Default values to be used from tests in . + /// + private static readonly IReadOnlyDictionary DefaultValues = new Dictionary + { + [typeof(string)] = "Hello world", + [typeof(Exception)] = new Exception("Test"), + [typeof(object)] = new object(), + [typeof(int)] = 42, + [typeof(CancellationToken)] = default(CancellationToken) + }; + + [TestCategory("Guard")] + [TestMethod] + [DataRow(typeof(ArrayTypeMismatchException))] + [DataRow(typeof(ArgumentException))] + [DataRow(typeof(ArgumentNullException))] + [DataRow(typeof(ArgumentOutOfRangeException))] + [DataRow(typeof(ExternalException))] + [DataRow(typeof(FormatException))] + [DataRow(typeof(InsufficientMemoryException))] + [DataRow(typeof(InvalidDataException))] + [DataRow(typeof(InvalidOperationException))] + [DataRow(typeof(LockRecursionException))] + [DataRow(typeof(MissingFieldException))] + [DataRow(typeof(MissingMemberException))] + [DataRow(typeof(MissingMethodException))] + [DataRow(typeof(NotSupportedException))] + [DataRow(typeof(ObjectDisposedException))] + [DataRow(typeof(OperationCanceledException))] + [DataRow(typeof(PlatformNotSupportedException))] + [DataRow(typeof(SynchronizationLockException))] + [DataRow(typeof(TimeoutException))] + [DataRow(typeof(UnauthorizedAccessException))] + [DataRow(typeof(Win32Exception))] + public void Test_ThrowHelper_Throw(Type exceptionType) + { + var methods = ( + from method in typeof(ThrowHelper).GetMethods(BindingFlags.Public | BindingFlags.Static) + where method.Name == $"Throw{exceptionType.Name}" + select method).ToArray(); + + foreach (var method in methods) + { + // Prepare the parameters with the default value + var parameters = ( + from parameter in method.GetParameters() + select DefaultValues[parameter.ParameterType]).ToArray(); + + // Invoke the throw method + try + { + method.Invoke(null, parameters); + } + catch (TargetInvocationException e) + { + Assert.IsInstanceOfType(e.InnerException, exceptionType); + } + } + } + } +} diff --git a/UnitTests/UnitTests.Shared/UnitTests.Shared.projitems b/UnitTests/UnitTests.Shared/UnitTests.Shared.projitems index c281bd27bdf..fd3d2006ef1 100644 --- a/UnitTests/UnitTests.Shared/UnitTests.Shared.projitems +++ b/UnitTests/UnitTests.Shared/UnitTests.Shared.projitems @@ -15,6 +15,7 @@ + From cd70d0dbfa80ea987a3bea4b0a0e676390bd6ed6 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 22 Jul 2020 00:11:28 +0200 Subject: [PATCH 16/19] Reverted HighPerformance changes Moved to related HighPerformance PR --- .../Enumerables/ReadOnlySpanEnumerable{T}.cs | 6 ++---- .../Enumerables/ReadOnlySpanTokenizer{T}.cs | 6 ++---- .../Enumerables/SpanEnumerable{T}.cs | 6 ++---- .../Enumerables/SpanTokenizer{T}.cs | 6 ++---- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanEnumerable{T}.cs b/Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanEnumerable{T}.cs index c732861d670..29d42924536 100644 --- a/Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanEnumerable{T}.cs +++ b/Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanEnumerable{T}.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -43,9 +42,8 @@ public ReadOnlySpanEnumerable(ReadOnlySpan span) /// Implements the duck-typed method. /// /// An instance targeting the current value. - [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ReadOnlySpanEnumerable GetEnumerator() => this; + public ReadOnlySpanEnumerable GetEnumerator() => this; /// /// Implements the duck-typed method. @@ -69,7 +67,7 @@ public bool MoveNext() /// /// Gets the duck-typed property. /// - public readonly Item Current + public Item Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get diff --git a/Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanTokenizer{T}.cs b/Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanTokenizer{T}.cs index 37bc6168f10..3977f5829f8 100644 --- a/Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanTokenizer{T}.cs +++ b/Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlySpanTokenizer{T}.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; namespace Microsoft.Toolkit.HighPerformance.Enumerables @@ -55,9 +54,8 @@ public ReadOnlySpanTokenizer(ReadOnlySpan span, T separator) /// Implements the duck-typed method. /// /// An instance targeting the current value. - [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly ReadOnlySpanTokenizer GetEnumerator() => this; + public ReadOnlySpanTokenizer GetEnumerator() => this; /// /// Implements the duck-typed method. @@ -96,7 +94,7 @@ public bool MoveNext() /// /// Gets the duck-typed property. /// - public readonly ReadOnlySpan Current + public ReadOnlySpan Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => this.span.Slice(this.start, this.end - this.start); diff --git a/Microsoft.Toolkit.HighPerformance/Enumerables/SpanEnumerable{T}.cs b/Microsoft.Toolkit.HighPerformance/Enumerables/SpanEnumerable{T}.cs index 3648a5e5140..791f509339d 100644 --- a/Microsoft.Toolkit.HighPerformance/Enumerables/SpanEnumerable{T}.cs +++ b/Microsoft.Toolkit.HighPerformance/Enumerables/SpanEnumerable{T}.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -43,9 +42,8 @@ public SpanEnumerable(Span span) /// Implements the duck-typed method. /// /// An instance targeting the current value. - [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SpanEnumerable GetEnumerator() => this; + public SpanEnumerable GetEnumerator() => this; /// /// Implements the duck-typed method. @@ -69,7 +67,7 @@ public bool MoveNext() /// /// Gets the duck-typed property. /// - public readonly Item Current + public Item Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get diff --git a/Microsoft.Toolkit.HighPerformance/Enumerables/SpanTokenizer{T}.cs b/Microsoft.Toolkit.HighPerformance/Enumerables/SpanTokenizer{T}.cs index da8a9dce040..953eb535f0b 100644 --- a/Microsoft.Toolkit.HighPerformance/Enumerables/SpanTokenizer{T}.cs +++ b/Microsoft.Toolkit.HighPerformance/Enumerables/SpanTokenizer{T}.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; namespace Microsoft.Toolkit.HighPerformance.Enumerables @@ -55,9 +54,8 @@ public SpanTokenizer(Span span, T separator) /// Implements the duck-typed method. /// /// An instance targeting the current value. - [Pure] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly SpanTokenizer GetEnumerator() => this; + public SpanTokenizer GetEnumerator() => this; /// /// Implements the duck-typed method. @@ -96,7 +94,7 @@ public bool MoveNext() /// /// Gets the duck-typed property. /// - public readonly Span Current + public Span Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => this.span.Slice(this.start, this.end - this.start); From 7c7098ada9d7e3f06c59f3afd2b722311556e236 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 26 Jul 2020 14:01:28 +0200 Subject: [PATCH 17/19] Code refactoring and restructuring --- .../ThrowHelper.Guard.Collection.Generic.cs} | 0 .../ThrowHelper.Guard.Comparable.Generic.cs} | 0 .../ThrowHelper.Guard.Comparable.Numeric.cs} | 0 .../ThrowHelper.Guard.IO.cs} | 0 .../ThrowHelper.Guard.String.cs} | 0 .../ThrowHelper.Guard.Tasks.cs} | 0 .../Internals/ThrowHelper.Guard.cs | 231 ++++++ .../ThrowHelper.ThrowExceptions.cs | 685 ------------------ Microsoft.Toolkit/Diagnostics/ThrowHelper.cs | 656 ++++++++++++++--- 9 files changed, 786 insertions(+), 786 deletions(-) rename Microsoft.Toolkit/Diagnostics/{ThrowHelper.Collection.Generic.cs => Internals/ThrowHelper.Guard.Collection.Generic.cs} (100%) rename Microsoft.Toolkit/Diagnostics/{ThrowHelper.Comparable.Generic.cs => Internals/ThrowHelper.Guard.Comparable.Generic.cs} (100%) rename Microsoft.Toolkit/Diagnostics/{ThrowHelper.Comparable.Numeric.cs => Internals/ThrowHelper.Guard.Comparable.Numeric.cs} (100%) rename Microsoft.Toolkit/Diagnostics/{ThrowHelper.IO.cs => Internals/ThrowHelper.Guard.IO.cs} (100%) rename Microsoft.Toolkit/Diagnostics/{ThrowHelper.String.cs => Internals/ThrowHelper.Guard.String.cs} (100%) rename Microsoft.Toolkit/Diagnostics/{ThrowHelper.Tasks.cs => Internals/ThrowHelper.Guard.Tasks.cs} (100%) create mode 100644 Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs delete mode 100644 Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Collection.Generic.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs rename to Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Collection.Generic.cs diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Generic.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs rename to Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Generic.cs diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Numeric.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs rename to Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Numeric.cs diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.IO.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs rename to Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.IO.cs diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.String.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs rename to Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.String.cs diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Tasks.cs similarity index 100% rename from Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs rename to Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Tasks.cs diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs new file mode 100644 index 00000000000..0ba836dc488 --- /dev/null +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs @@ -0,0 +1,231 @@ +// 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; +using System.Diagnostics.Contracts; +using System.Runtime.CompilerServices; +using Microsoft.Toolkit.Extensions; + +#nullable enable + +namespace Microsoft.Toolkit.Diagnostics +{ + /// + /// Helper methods to efficiently throw exceptions. + /// + public static partial class ThrowHelper + { + /// + /// Returns a formatted representation of the input value. + /// + /// The input to format. + /// A formatted representation of to display in error messages. + [Pure] + private static string ToAssertString(this object? obj) + { + return obj switch + { + string _ => $"\"{obj}\"", + null => "null", + _ => $"<{obj}>" + }; + } + + /// + /// Throws an when (where is ) fails. + /// + /// The type of the input value. + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsNull(T value, string name) + where T : class + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be null, was {value.ToAssertString()} ({value.GetType().ToTypeString()})"); + } + + /// + /// Throws an when (where is ) fails. + /// + /// The type of the input value. + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsNull(T? value, string name) + where T : struct + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T?).ToTypeString()}) must be null, was {value.ToAssertString()} ({typeof(T).ToTypeString()})"); + } + + /// + /// Throws an when fails. + /// + /// The type of the input value. + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentNullExceptionForIsNotNull(string name) + { + ThrowArgumentNullException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be not null)"); + } + + /// + /// Throws an when fails. + /// + /// The type of the input value. + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsOfType(object value, string name) + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); + } + + /// + /// Throws an when fails. + /// + /// The type of the input value. + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsNotOfType(object value, string name) + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); + } + + /// + /// Throws an when fails. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsOfType(object value, Type type, string name) + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); + } + + /// + /// Throws an when fails. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsNotOfType(object value, Type type, string name) + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); + } + + /// + /// Throws an when fails. + /// + /// The type being checked against. + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsAssignableToType(object value, string name) + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); + } + + /// + /// Throws an when fails. + /// + /// The type being checked against. + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value, string name) + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); + } + + /// + /// Throws an when fails. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsAssignableToType(object value, Type type, string name) + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); + } + + /// + /// Throws an when fails. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value, Type type, string name) + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); + } + + /// + /// Throws an when fails. + /// + /// The type of input values being compared. + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForsBitwiseEqualTo(T value, T target, string name) + where T : unmanaged + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) is not a bitwise match, was <{value.ToHexString()}> instead of <{target.ToHexString()}>"); + } + + /// + /// Throws an when fails. + /// + /// The type of input value being compared. + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsReferenceEqualTo(string name) + where T : class + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be the same instance as the target object"); + } + + /// + /// Throws an when fails. + /// + /// The type of input value being compared. + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsReferenceNotEqualTo(string name) + where T : class + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be the same instance as the target object"); + } + + /// + /// Throws an when fails. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsTrue(string name) + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false"); + } + + /// + /// Throws an when fails. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsTrue(string name, string message) + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false: {message.ToAssertString()}"); + } + + /// + /// Throws an when fails. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsFalse(string name) + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true"); + } + + /// + /// Throws an when fails. + /// + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForIsFalse(string name, string message) + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true: {message.ToAssertString()}"); + } + } +} diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs deleted file mode 100644 index 103c3ef12ad..00000000000 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.ThrowExceptions.cs +++ /dev/null @@ -1,685 +0,0 @@ -// 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.ComponentModel; -using System.Diagnostics.CodeAnalysis; -using System.IO; -using System.Runtime.InteropServices; -using System.Threading; - -#nullable enable - -namespace Microsoft.Toolkit.Diagnostics -{ - /// - /// Helper methods to efficiently throw exceptions. - /// - public static partial class ThrowHelper - { - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowArrayTypeMismatchException(string message) - { - throw new ArrayTypeMismatchException(message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The inner to include. - /// Thrown with the specified parameters. - [DoesNotReturn] - public static void ThrowArrayTypeMismatchException(string message, Exception innerException) - { - throw new ArrayTypeMismatchException(message, innerException); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowArgumentException(string message) - { - throw new ArgumentException(message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The inner to include. - /// Thrown with the specified parameters. - [DoesNotReturn] - public static void ThrowArgumentException(string message, Exception innerException) - { - throw new ArgumentException(message, innerException); - } - - /// - /// Throws a new . - /// - /// The argument name. - /// The message to include in the exception. - /// Thrown with the specified parameters. - [DoesNotReturn] - public static void ThrowArgumentException(string name, string message) - { - throw new ArgumentException(message, name); - } - - /// - /// Throws a new . - /// - /// The argument name. - /// The message to include in the exception. - /// The inner to include. - /// Thrown with the specified parameters. - [DoesNotReturn] - public static void ThrowArgumentException(string name, string message, Exception innerException) - { - throw new ArgumentException(message, name, innerException); - } - - /// - /// Throws a new . - /// - /// The argument name. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowArgumentNullException(string name) - { - throw new ArgumentNullException(name); - } - - /// - /// Throws a new . - /// - /// The argument name. - /// The inner to include. - /// Thrown with the specified parameters. - [DoesNotReturn] - public static void ThrowArgumentNullException(string name, Exception innerException) - { - throw new ArgumentNullException(name, innerException); - } - - /// - /// Throws a new . - /// - /// The argument name. - /// The message to include in the exception. - /// Thrown with the specified parameters. - [DoesNotReturn] - public static void ThrowArgumentNullException(string name, string message) - { - throw new ArgumentNullException(name, message); - } - - /// - /// Throws a new . - /// - /// The argument name. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowArgumentOutOfRangeException(string name) - { - throw new ArgumentOutOfRangeException(name); - } - - /// - /// Throws a new . - /// - /// The argument name. - /// The inner to include. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowArgumentOutOfRangeException(string name, Exception innerException) - { - throw new ArgumentOutOfRangeException(name, innerException); - } - - /// - /// Throws a new . - /// - /// The argument name. - /// The message to include in the exception. - /// Thrown with the specified parameters. - [DoesNotReturn] - public static void ThrowArgumentOutOfRangeException(string name, string message) - { - throw new ArgumentOutOfRangeException(name, message); - } - - /// - /// Throws a new . - /// - /// The argument name. - /// The current argument value. - /// The message to include in the exception. - /// Thrown with the specified parameters. - [DoesNotReturn] - public static void ThrowArgumentOutOfRangeException(string name, object value, string message) - { - throw new ArgumentOutOfRangeException(name, value, message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowExternalException(string message) - { - throw new ExternalException(message); - } - - /// - /// Throws a new . - /// - /// The argument name. - /// The inner to include. - /// Thrown with the specified parameters. - [DoesNotReturn] - public static void ThrowExternalException(string message, Exception innerException) - { - throw new ExternalException(message, innerException); - } - - /// - /// Throws a new . - /// - /// The argument name. - /// The HRESULT of the errror to include. - /// Thrown with the specified parameters. - [DoesNotReturn] - public static void ThrowExternalException(string message, int error) - { - throw new ExternalException(message, error); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowFormatException(string message) - { - throw new FormatException(message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The inner to include. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowFormatException(string message, Exception innerException) - { - throw new FormatException(message, innerException); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowInsufficientMemoryException(string message) - { - throw new InsufficientMemoryException(message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The inner to include. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowInsufficientMemoryException(string message, Exception innerException) - { - throw new InsufficientMemoryException(message, innerException); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowInvalidDataException(string message) - { - throw new InvalidDataException(message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The inner to include. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowInvalidDataException(string message, Exception innerException) - { - throw new InvalidDataException(message, innerException); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowInvalidOperationException(string message) - { - throw new InvalidOperationException(message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The inner to include. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowInvalidOperationException(string message, Exception innerException) - { - throw new InvalidOperationException(message, innerException); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowLockRecursionException(string message) - { - throw new LockRecursionException(message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The inner to include. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowLockRecursionException(string message, Exception innerException) - { - throw new LockRecursionException(message, innerException); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowMissingFieldException(string message) - { - throw new MissingFieldException(message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The inner to include. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowMissingFieldException(string message, Exception innerException) - { - throw new MissingFieldException(message, innerException); - } - - /// - /// Throws a new . - /// - /// The target class being inspected. - /// The target field being retrieved. - /// Thrown with the specified parameters. - [DoesNotReturn] - public static void ThrowMissingFieldException(string className, string fieldName) - { - throw new MissingFieldException(className, fieldName); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowMissingMemberException(string message) - { - throw new MissingMemberException(message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The inner to include. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowMissingMemberException(string message, Exception innerException) - { - throw new MissingMemberException(message, innerException); - } - - /// - /// Throws a new . - /// - /// The target class being inspected. - /// The target member being retrieved. - /// Thrown with the specified parameters. - [DoesNotReturn] - public static void ThrowMissingMemberException(string className, string memberName) - { - throw new MissingMemberException(className, memberName); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowMissingMethodException(string message) - { - throw new MissingMethodException(message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The inner to include. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowMissingMethodException(string message, Exception innerException) - { - throw new MissingMethodException(message, innerException); - } - - /// - /// Throws a new . - /// - /// The target class being inspected. - /// The target method being retrieved. - /// Thrown with the specified parameters. - [DoesNotReturn] - public static void ThrowMissingMethodException(string className, string methodName) - { - throw new MissingMethodException(className, methodName); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowNotSupportedException(string message) - { - throw new NotSupportedException(message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The inner to include. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowNotSupportedException(string message, Exception innerException) - { - throw new NotSupportedException(message, innerException); - } - - /// - /// Throws a new . - /// - /// The name of the disposed object. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowObjectDisposedException(string objectName) - { - throw new ObjectDisposedException(objectName); - } - - /// - /// Throws a new . - /// - /// The name of the disposed object. - /// The inner to include. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowObjectDisposedException(string objectName, Exception innerException) - { - throw new ObjectDisposedException(objectName, innerException); - } - - /// - /// Throws a new . - /// - /// The name of the disposed object. - /// The message to include in the exception. - /// Thrown with the specified parameters. - [DoesNotReturn] - public static void ThrowObjectDisposedException(string objectName, string message) - { - throw new ObjectDisposedException(objectName, message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowOperationCanceledException(string message) - { - throw new OperationCanceledException(message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The inner to include. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowOperationCanceledException(string message, Exception innerException) - { - throw new OperationCanceledException(message, innerException); - } - - /// - /// Throws a new . - /// - /// The in use. - /// Thrown with the specified parameters. - [DoesNotReturn] - public static void ThrowOperationCanceledException(CancellationToken token) - { - throw new OperationCanceledException(token); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The in use. - /// Thrown with the specified parameters. - [DoesNotReturn] - public static void ThrowOperationCanceledException(string message, CancellationToken token) - { - throw new OperationCanceledException(message, token); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The inner to include. - /// The in use. - /// Thrown with the specified parameters. - [DoesNotReturn] - public static void ThrowOperationCanceledException(string message, Exception innerException, CancellationToken token) - { - throw new OperationCanceledException(message, innerException, token); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowPlatformNotSupportedException(string message) - { - throw new PlatformNotSupportedException(message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The inner to include. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowPlatformNotSupportedException(string message, Exception innerException) - { - throw new PlatformNotSupportedException(message, innerException); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowSynchronizationLockException(string message) - { - throw new SynchronizationLockException(message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The inner to include. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowSynchronizationLockException(string message, Exception innerException) - { - throw new SynchronizationLockException(message, innerException); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowTimeoutException(string message) - { - throw new TimeoutException(message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The inner to include. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowTimeoutException(string message, Exception innerException) - { - throw new TimeoutException(message, innerException); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowUnauthorizedAccessException(string message) - { - throw new UnauthorizedAccessException(message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The inner to include. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowUnauthorizedAccessException(string message, Exception innerException) - { - throw new UnauthorizedAccessException(message, innerException); - } - - /// - /// Throws a new . - /// - /// The Win32 error code associated with this exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowWin32Exception(int error) - { - throw new Win32Exception(error); - } - - /// - /// Throws a new . - /// - /// The Win32 error code associated with this exception. - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowWin32Exception(int error, string message) - { - throw new Win32Exception(error, message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowWin32Exception(string message) - { - throw new Win32Exception(message); - } - - /// - /// Throws a new . - /// - /// The message to include in the exception. - /// The inner to include. - /// Thrown with the specified parameter. - [DoesNotReturn] - public static void ThrowWin32Exception(string message, Exception innerException) - { - throw new Win32Exception(message, innerException); - } - } -} diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs index 0ba836dc488..103c3ef12ad 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs @@ -3,10 +3,11 @@ // See the LICENSE file in the project root for more information. using System; +using System.ComponentModel; using System.Diagnostics.CodeAnalysis; -using System.Diagnostics.Contracts; -using System.Runtime.CompilerServices; -using Microsoft.Toolkit.Extensions; +using System.IO; +using System.Runtime.InteropServices; +using System.Threading; #nullable enable @@ -18,214 +19,667 @@ namespace Microsoft.Toolkit.Diagnostics public static partial class ThrowHelper { /// - /// Returns a formatted representation of the input value. + /// Throws a new . /// - /// The input to format. - /// A formatted representation of to display in error messages. - [Pure] - private static string ToAssertString(this object? obj) + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowArrayTypeMismatchException(string message) + { + throw new ArrayTypeMismatchException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowArrayTypeMismatchException(string message, Exception innerException) + { + throw new ArrayTypeMismatchException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowArgumentException(string message) + { + throw new ArgumentException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowArgumentException(string message, Exception innerException) + { + throw new ArgumentException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The argument name. + /// The message to include in the exception. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowArgumentException(string name, string message) + { + throw new ArgumentException(message, name); + } + + /// + /// Throws a new . + /// + /// The argument name. + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowArgumentException(string name, string message, Exception innerException) + { + throw new ArgumentException(message, name, innerException); + } + + /// + /// Throws a new . + /// + /// The argument name. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowArgumentNullException(string name) + { + throw new ArgumentNullException(name); + } + + /// + /// Throws a new . + /// + /// The argument name. + /// The inner to include. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowArgumentNullException(string name, Exception innerException) + { + throw new ArgumentNullException(name, innerException); + } + + /// + /// Throws a new . + /// + /// The argument name. + /// The message to include in the exception. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowArgumentNullException(string name, string message) + { + throw new ArgumentNullException(name, message); + } + + /// + /// Throws a new . + /// + /// The argument name. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeException(string name) + { + throw new ArgumentOutOfRangeException(name); + } + + /// + /// Throws a new . + /// + /// The argument name. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeException(string name, Exception innerException) + { + throw new ArgumentOutOfRangeException(name, innerException); + } + + /// + /// Throws a new . + /// + /// The argument name. + /// The message to include in the exception. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeException(string name, string message) + { + throw new ArgumentOutOfRangeException(name, message); + } + + /// + /// Throws a new . + /// + /// The argument name. + /// The current argument value. + /// The message to include in the exception. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowArgumentOutOfRangeException(string name, object value, string message) + { + throw new ArgumentOutOfRangeException(name, value, message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowExternalException(string message) + { + throw new ExternalException(message); + } + + /// + /// Throws a new . + /// + /// The argument name. + /// The inner to include. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowExternalException(string message, Exception innerException) + { + throw new ExternalException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The argument name. + /// The HRESULT of the errror to include. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowExternalException(string message, int error) + { + throw new ExternalException(message, error); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowFormatException(string message) + { + throw new FormatException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowFormatException(string message, Exception innerException) + { + throw new FormatException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowInsufficientMemoryException(string message) + { + throw new InsufficientMemoryException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowInsufficientMemoryException(string message, Exception innerException) + { + throw new InsufficientMemoryException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowInvalidDataException(string message) + { + throw new InvalidDataException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowInvalidDataException(string message, Exception innerException) + { + throw new InvalidDataException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowInvalidOperationException(string message) + { + throw new InvalidOperationException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowInvalidOperationException(string message, Exception innerException) + { + throw new InvalidOperationException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowLockRecursionException(string message) + { + throw new LockRecursionException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowLockRecursionException(string message, Exception innerException) + { + throw new LockRecursionException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowMissingFieldException(string message) + { + throw new MissingFieldException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowMissingFieldException(string message, Exception innerException) + { + throw new MissingFieldException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The target class being inspected. + /// The target field being retrieved. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowMissingFieldException(string className, string fieldName) + { + throw new MissingFieldException(className, fieldName); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowMissingMemberException(string message) + { + throw new MissingMemberException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowMissingMemberException(string message, Exception innerException) + { + throw new MissingMemberException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The target class being inspected. + /// The target member being retrieved. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowMissingMemberException(string className, string memberName) + { + throw new MissingMemberException(className, memberName); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowMissingMethodException(string message) + { + throw new MissingMethodException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowMissingMethodException(string message, Exception innerException) + { + throw new MissingMethodException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The target class being inspected. + /// The target method being retrieved. + /// Thrown with the specified parameters. + [DoesNotReturn] + public static void ThrowMissingMethodException(string className, string methodName) + { + throw new MissingMethodException(className, methodName); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowNotSupportedException(string message) + { + throw new NotSupportedException(message); + } + + /// + /// Throws a new . + /// + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowNotSupportedException(string message, Exception innerException) + { + throw new NotSupportedException(message, innerException); + } + + /// + /// Throws a new . + /// + /// The name of the disposed object. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowObjectDisposedException(string objectName) + { + throw new ObjectDisposedException(objectName); + } + + /// + /// Throws a new . + /// + /// The name of the disposed object. + /// The inner to include. + /// Thrown with the specified parameter. + [DoesNotReturn] + public static void ThrowObjectDisposedException(string objectName, Exception innerException) { - return obj switch - { - string _ => $"\"{obj}\"", - null => "null", - _ => $"<{obj}>" - }; + throw new ObjectDisposedException(objectName, innerException); } /// - /// Throws an when (where is ) fails. + /// Throws a new . /// - /// The type of the input value. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The name of the disposed object. + /// The message to include in the exception. + /// Thrown with the specified parameters. [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNull(T value, string name) - where T : class + public static void ThrowObjectDisposedException(string objectName, string message) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be null, was {value.ToAssertString()} ({value.GetType().ToTypeString()})"); + throw new ObjectDisposedException(objectName, message); } /// - /// Throws an when (where is ) fails. + /// Throws a new . /// - /// The type of the input value. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// Thrown with the specified parameter. [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNull(T? value, string name) - where T : struct + public static void ThrowOperationCanceledException(string message) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T?).ToTypeString()}) must be null, was {value.ToAssertString()} ({typeof(T).ToTypeString()})"); + throw new OperationCanceledException(message); } /// - /// Throws an when fails. + /// Throws a new . /// - /// The type of the input value. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. [DoesNotReturn] - internal static void ThrowArgumentNullExceptionForIsNotNull(string name) + public static void ThrowOperationCanceledException(string message, Exception innerException) { - ThrowArgumentNullException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be not null)"); + throw new OperationCanceledException(message, innerException); } /// - /// Throws an when fails. + /// Throws a new . /// - /// The type of the input value. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The in use. + /// Thrown with the specified parameters. [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsOfType(object value, string name) + public static void ThrowOperationCanceledException(CancellationToken token) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new OperationCanceledException(token); } /// - /// Throws an when fails. + /// Throws a new . /// - /// The type of the input value. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// The in use. + /// Thrown with the specified parameters. [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotOfType(object value, string name) + public static void ThrowOperationCanceledException(string message, CancellationToken token) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be of type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new OperationCanceledException(message, token); } /// - /// Throws an when fails. + /// Throws a new . /// - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// The inner to include. + /// The in use. + /// Thrown with the specified parameters. [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsOfType(object value, Type type, string name) + public static void ThrowOperationCanceledException(string message, Exception innerException, CancellationToken token) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new OperationCanceledException(message, innerException, token); } /// - /// Throws an when fails. + /// Throws a new . /// - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// Thrown with the specified parameter. [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotOfType(object value, Type type, string name) + public static void ThrowPlatformNotSupportedException(string message) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be of type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new PlatformNotSupportedException(message); } /// - /// Throws an when fails. + /// Throws a new . /// - /// The type being checked against. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsAssignableToType(object value, string name) + public static void ThrowPlatformNotSupportedException(string message, Exception innerException) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new PlatformNotSupportedException(message, innerException); } /// - /// Throws an when fails. + /// Throws a new . /// - /// The type being checked against. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// Thrown with the specified parameter. [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value, string name) + public static void ThrowSynchronizationLockException(string message) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be assignable to type {typeof(T).ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new SynchronizationLockException(message); } /// - /// Throws an when fails. + /// Throws a new . /// - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsAssignableToType(object value, Type type, string name) + public static void ThrowSynchronizationLockException(string message, Exception innerException) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new SynchronizationLockException(message, innerException); } /// - /// Throws an when fails. + /// Throws a new . /// - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// Thrown with the specified parameter. [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value, Type type, string name) + public static void ThrowTimeoutException(string message) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); + throw new TimeoutException(message); } /// - /// Throws an when fails. + /// Throws a new . /// - /// The type of input values being compared. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. [DoesNotReturn] - internal static void ThrowArgumentExceptionForsBitwiseEqualTo(T value, T target, string name) - where T : unmanaged + public static void ThrowTimeoutException(string message, Exception innerException) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) is not a bitwise match, was <{value.ToHexString()}> instead of <{target.ToHexString()}>"); + throw new TimeoutException(message, innerException); } /// - /// Throws an when fails. + /// Throws a new . /// - /// The type of input value being compared. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// Thrown with the specified parameter. [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsReferenceEqualTo(string name) - where T : class + public static void ThrowUnauthorizedAccessException(string message) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be the same instance as the target object"); + throw new UnauthorizedAccessException(message); } /// - /// Throws an when fails. + /// Throws a new . /// - /// The type of input value being compared. - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsReferenceNotEqualTo(string name) - where T : class + public static void ThrowUnauthorizedAccessException(string message, Exception innerException) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be the same instance as the target object"); + throw new UnauthorizedAccessException(message, innerException); } /// - /// Throws an when fails. + /// Throws a new . /// - [MethodImpl(MethodImplOptions.NoInlining)] + /// The Win32 error code associated with this exception. + /// Thrown with the specified parameter. [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsTrue(string name) + public static void ThrowWin32Exception(int error) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false"); + throw new Win32Exception(error); } /// - /// Throws an when fails. + /// Throws a new . /// - [MethodImpl(MethodImplOptions.NoInlining)] + /// The Win32 error code associated with this exception. + /// The message to include in the exception. + /// Thrown with the specified parameter. [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsTrue(string name, string message) + public static void ThrowWin32Exception(int error, string message) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false: {message.ToAssertString()}"); + throw new Win32Exception(error, message); } /// - /// Throws an when fails. + /// Throws a new . /// - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// Thrown with the specified parameter. [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsFalse(string name) + public static void ThrowWin32Exception(string message) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true"); + throw new Win32Exception(message); } /// - /// Throws an when fails. + /// Throws a new . /// - [MethodImpl(MethodImplOptions.NoInlining)] + /// The message to include in the exception. + /// The inner to include. + /// Thrown with the specified parameter. [DoesNotReturn] - internal static void ThrowArgumentExceptionForIsFalse(string name, string message) + public static void ThrowWin32Exception(string message, Exception innerException) { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true: {message.ToAssertString()}"); + throw new Win32Exception(message, innerException); } } } From 670c8338e7040acade36f87b80c6e0a1f2c55596 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 28 Jul 2020 01:53:30 +0200 Subject: [PATCH 18/19] Code tweaks to support #3293 --- Microsoft.Toolkit/Diagnostics/ThrowHelper.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs index 103c3ef12ad..2338f17a31d 100644 --- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs +++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs @@ -6,7 +6,9 @@ using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.IO; +#if !NETSTANDARD1_4 using System.Runtime.InteropServices; +#endif using System.Threading; #nullable enable @@ -172,6 +174,7 @@ public static void ThrowArgumentOutOfRangeException(string name, object value, s throw new ArgumentOutOfRangeException(name, value, message); } +#if !NETSTANDARD1_4 /// /// Throws a new . /// @@ -206,6 +209,7 @@ public static void ThrowExternalException(string message, int error) { throw new ExternalException(message, error); } +#endif /// /// Throws a new . @@ -230,6 +234,7 @@ public static void ThrowFormatException(string message, Exception innerException throw new FormatException(message, innerException); } +#if !NETSTANDARD1_4 /// /// Throws a new . /// @@ -252,6 +257,7 @@ public static void ThrowInsufficientMemoryException(string message, Exception in { throw new InsufficientMemoryException(message, innerException); } +#endif /// /// Throws a new . @@ -345,6 +351,7 @@ public static void ThrowMissingFieldException(string message, Exception innerExc throw new MissingFieldException(message, innerException); } +#if !NETSTANDARD1_4 /// /// Throws a new . /// @@ -356,6 +363,7 @@ public static void ThrowMissingFieldException(string className, string fieldName { throw new MissingFieldException(className, fieldName); } +#endif /// /// Throws a new . @@ -380,6 +388,7 @@ public static void ThrowMissingMemberException(string message, Exception innerEx throw new MissingMemberException(message, innerException); } +#if !NETSTANDARD1_4 /// /// Throws a new . /// @@ -391,6 +400,7 @@ public static void ThrowMissingMemberException(string className, string memberNa { throw new MissingMemberException(className, memberName); } +#endif /// /// Throws a new . @@ -415,6 +425,7 @@ public static void ThrowMissingMethodException(string message, Exception innerEx throw new MissingMethodException(message, innerException); } +#if !NETSTANDARD1_4 /// /// Throws a new . /// @@ -426,6 +437,7 @@ public static void ThrowMissingMethodException(string className, string methodNa { throw new MissingMethodException(className, methodName); } +#endif /// /// Throws a new . From 759d09b5d8b329ffffe9ec107b5ac7274f11adaf Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 12 Aug 2020 13:36:40 +0200 Subject: [PATCH 19/19] Fixed a build error, minor refactoring --- .../ThrowHelper.Guard.Comparable.Generic.cs | 12 ++++++++++++ .../Diagnostics/Internals/ThrowHelper.Guard.cs | 12 ------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Generic.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Generic.cs index 030ede72c30..11b06a99890 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Generic.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.Comparable.Generic.cs @@ -62,6 +62,18 @@ internal static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be equal to {target.ToAssertString()}, was {value.ToAssertString()}"); } + /// + /// Throws an when fails. + /// + /// The type of input values being compared. + [MethodImpl(MethodImplOptions.NoInlining)] + [DoesNotReturn] + internal static void ThrowArgumentExceptionForBitwiseEqualTo(T value, T target, string name) + where T : unmanaged + { + ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) is not a bitwise match, was <{value.ToHexString()}> instead of <{target.ToHexString()}>"); + } + /// /// Throws an when fails. /// diff --git a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs index 0ba836dc488..fda9336b0fe 100644 --- a/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs +++ b/Microsoft.Toolkit/Diagnostics/Internals/ThrowHelper.Guard.cs @@ -152,18 +152,6 @@ internal static void ThrowArgumentExceptionForIsNotAssignableToType(object value ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must not be assignable to type {type.ToTypeString()}, was {value.GetType().ToTypeString()}"); } - /// - /// Throws an when fails. - /// - /// The type of input values being compared. - [MethodImpl(MethodImplOptions.NoInlining)] - [DoesNotReturn] - internal static void ThrowArgumentExceptionForsBitwiseEqualTo(T value, T target, string name) - where T : unmanaged - { - ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) is not a bitwise match, was <{value.ToHexString()}> instead of <{target.ToHexString()}>"); - } - /// /// Throws an when fails. ///