Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4ea26c5
Added missing attributes/annotations
Sergio0694 Jun 14, 2020
ee8c71c
Initial update on ThrowHelper visibility
Sergio0694 Jun 14, 2020
a90acfc
Improved construction of ArgumentOutOfRangeException-s
Sergio0694 Jun 14, 2020
b63b34b
Made current thrower public, minor API additions
Sergio0694 Jun 14, 2020
33b83ab
Added more throw helper APIs
Sergio0694 Jun 14, 2020
480b860
Removed some throw helpers according to docs
Sergio0694 Jun 14, 2020
c9a9360
Simplified XML docs
Sergio0694 Jun 15, 2020
0172ae5
Added overloads with inner exception parameters
Sergio0694 Jun 15, 2020
9031384
Added more exceptions
Sergio0694 Jun 15, 2020
2cce132
Added ArrayTypeMismatchException throw APIs
Sergio0694 Jun 17, 2020
e4693b2
Merge branch 'master' into feature/throw-helpers
Sergio0694 Jun 22, 2020
39f417c
Merge branch 'master' into feature/throw-helpers
Sergio0694 Jun 24, 2020
e517751
Merge branch 'master' into feature/throw-helpers
Sergio0694 Jun 26, 2020
18d294c
Merge branch 'master' into feature/throw-helpers
Sergio0694 Jun 30, 2020
a8a277f
Merge branch 'master' into feature/throw-helpers
Sergio0694 Jul 10, 2020
ffc5d8d
Merge branch 'master' into feature/throw-helpers
Sergio0694 Jul 13, 2020
53c6841
Code refactoring, moved attributes to root
Sergio0694 Jul 16, 2020
c300e76
Merge branch 'master' into feature/throw-helpers
Sergio0694 Jul 21, 2020
85492a0
Merge branch 'master' into feature/throw-helpers
Sergio0694 Jul 21, 2020
443947d
Improved XML summary for ThrowHelper class
Sergio0694 Jul 21, 2020
f70ae0c
Added [StackTraceHidden] attribute
Sergio0694 Jul 21, 2020
ae8ea90
Revert "Added [StackTraceHidden] attribute"
Sergio0694 Jul 21, 2020
418c246
Added unit tests for new ThrowHelper APIs
Sergio0694 Jul 21, 2020
cd70d0d
Reverted HighPerformance changes
Sergio0694 Jul 21, 2020
bd93302
Merge branch 'master' into feature/throw-helpers
Sergio0694 Jul 26, 2020
7c7098a
Code refactoring and restructuring
Sergio0694 Jul 26, 2020
703ffbc
Merge branch 'master' into feature/throw-helpers
Sergio0694 Jul 26, 2020
db8af7f
Merge remote-tracking branch 'upstream/master' into feature/throw-hel…
Sergio0694 Jul 27, 2020
670c833
Code tweaks to support #3293
Sergio0694 Jul 27, 2020
ca5a07f
Merge branch 'master' into feature/throw-helpers
Sergio0694 Aug 8, 2020
759d09b
Fixed a build error, minor refactoring
Sergio0694 Aug 12, 2020
fd7415d
Merge branch 'master' into feature/throw-helpers
Sergio0694 Aug 12, 2020
96991c2
Merge branch 'master' into feature/throw-helpers
azchohfi Aug 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Added [StackTraceHidden] attribute"
This reverts commit f70ae0c.
Unfortunately the attribute is actually matched by type and not just by name like the others. We should reintroduce this once either dotnet/runtime#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.
  • Loading branch information
Sergio0694 committed Jul 21, 2020
commit ae8ea9022ad9e02eb562999c28dc00a2abc871e9
16 changes: 0 additions & 16 deletions Microsoft.Toolkit/Attributes/StackTraceHiddenAttribute.cs

This file was deleted.

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,7 +26,6 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentExceptionForIsEmpty<T>(<#=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()}");
Expand All @@ -38,7 +36,6 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(<#=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()}");
Expand All @@ -49,7 +46,6 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(<#=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()}");
Expand All @@ -60,7 +56,6 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(<#=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()}");
Expand All @@ -71,7 +66,6 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(<#=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()}");
Expand All @@ -82,7 +76,6 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentExceptionForHasSizeLessThan<T>(<#=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()}");
Expand All @@ -93,7 +86,6 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(<#=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()}");
Expand All @@ -104,7 +96,6 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentExceptionForHasSizeEqualTo<T>(<#=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()}");
Expand All @@ -115,7 +106,6 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(<#=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()}");
Expand All @@ -126,7 +116,6 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(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()}");
Expand All @@ -137,7 +126,6 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(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()}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,7 +23,6 @@ public static partial class ThrowHelper
/// <remarks>This method is needed because <see cref="Span{T}"/> can't be used as a generic type parameter.</remarks>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentExceptionForIsNotEmptyWithSpan<T>(string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span<T>).ToTypeString()}) must not be empty");
Expand All @@ -37,7 +35,6 @@ internal static void ThrowArgumentExceptionForIsNotEmptyWithSpan<T>(string name)
/// <remarks>This method is needed because <see cref="ReadOnlySpan{T}"/> can't be used as a generic type parameter.</remarks>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan<T>(string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan<T>).ToTypeString()}) must not be empty");
Expand All @@ -49,7 +46,6 @@ internal static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan<T>(stri
/// <typeparam name="T">The item of items in the input collection.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentExceptionForIsNotEmpty<T>(string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be empty");
Expand Down
15 changes: 0 additions & 15 deletions Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,7 +22,6 @@ public static partial class ThrowHelper
/// <typeparam name="T">The type of <see langword="struct"/> value type being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentExceptionForIsDefault<T>(T value, string name)
where T : struct
{
Expand All @@ -36,7 +34,6 @@ internal static void ThrowArgumentExceptionForIsDefault<T>(T value, string name)
/// <typeparam name="T">The type of <see langword="struct"/> value type being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentExceptionForIsNotDefault<T>(string name)
where T : struct
{
Expand All @@ -49,7 +46,6 @@ internal static void ThrowArgumentExceptionForIsNotDefault<T>(string name)
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentExceptionForIsEqualTo<T>(T value, T target, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be equal to {target.ToAssertString()}, was {value.ToAssertString()}");
Expand All @@ -61,7 +57,6 @@ internal static void ThrowArgumentExceptionForIsEqualTo<T>(T value, T target, st
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentExceptionForIsNotEqualTo<T>(T value, T target, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be equal to {target.ToAssertString()}, was {value.ToAssertString()}");
Expand All @@ -73,7 +68,6 @@ internal static void ThrowArgumentExceptionForIsNotEqualTo<T>(T value, T target,
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentOutOfRangeExceptionForIsLessThan<T>(T value, T maximum, string name)
{
ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be less than {maximum.ToAssertString()}, was {value.ToAssertString()}");
Expand All @@ -85,7 +79,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsLessThan<T>(T value, T
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo<T>(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()}");
Expand All @@ -97,7 +90,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo<T>(T
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan<T>(T value, T minimum, string name)
{
ThrowArgumentOutOfRangeException(name, value!, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be greater than {minimum.ToAssertString()}, was {value.ToAssertString()}");
Expand All @@ -109,7 +101,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan<T>(T value
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo<T>(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()}");
Expand All @@ -121,7 +112,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo<T
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentOutOfRangeExceptionForIsInRange<T>(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()}");
Expand All @@ -133,7 +123,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsInRange<T>(T value, T
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRange<T>(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()}");
Expand All @@ -145,7 +134,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRange<T>(T value,
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentOutOfRangeExceptionForIsBetween<T>(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()}");
Expand All @@ -157,7 +145,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsBetween<T>(T value, T
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetween<T>(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()}");
Expand All @@ -169,7 +156,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetween<T>(T value,
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo<T>(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()}");
Expand All @@ -181,7 +167,6 @@ internal static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo<T>(T
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
[StackTraceHidden]
internal static void ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo<T>(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()}");
Expand Down
Loading