Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
212 changes: 106 additions & 106 deletions Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ using Microsoft.Toolkit.Extensions;
namespace Microsoft.Toolkit.Diagnostics
{
/// <summary>
/// Helper methods to throw exceptions
/// Helper methods to efficiently throw exceptions.
/// </summary>
internal static partial class ThrowHelper
public static partial class ThrowHelper
{
<#
GenerateTextForItems(EnumerableTypes, item =>
Expand All @@ -26,7 +26,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsEmpty<T>(<#=item.Type#> <#=item.Name#>, string name)
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 @@ -36,7 +36,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
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 @@ -46,7 +46,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForHasSizeNotEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
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 @@ -56,7 +56,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
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 @@ -66,7 +66,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
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 @@ -76,7 +76,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForHasSizeLessThan<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
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 @@ -86,7 +86,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
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 @@ -96,7 +96,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForHasSizeEqualTo<T>(<#=item.Type#> source, <#=item.DestinationType#> destination, string name)
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 @@ -106,7 +106,7 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForHasSizeLessThanOrEqualTo<T>(<#=item.Type#> source, <#=item.DestinationType#> destination, string name)
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 @@ -116,19 +116,19 @@ GenerateTextForItems(EnumerableTypes, item =>
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(int index, <#=item.Type#> <#=item.Name#>, string name)
internal static void ThrowArgumentOutOfRangeExceptionForIsInRangeFor<T>(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()}");
}

/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsNotInRangeFor{T}(int,T[],string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(int index, <#=item.Type#> <#=item.Name#>, string name)
internal static void ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor<T>(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()}");
}
<#
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
namespace Microsoft.Toolkit.Diagnostics
{
/// <summary>
/// Helper methods to throw exceptions
/// Helper methods to efficiently throw exceptions.
/// </summary>
internal static partial class ThrowHelper
public static partial class ThrowHelper
{
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotEmpty{T}(Span{T},string)"/> fails.
Expand All @@ -23,7 +23,7 @@ internal 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]
public static void ThrowArgumentExceptionForIsNotEmptyWithSpan<T>(string name)
internal static void ThrowArgumentExceptionForIsNotEmptyWithSpan<T>(string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span<T>).ToTypeString()}) must not be empty");
}
Expand All @@ -35,7 +35,7 @@ public 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]
public static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan<T>(string name)
internal static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan<T>(string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan<T>).ToTypeString()}) must not be empty");
}
Expand All @@ -46,7 +46,7 @@ public static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan<T>(string
/// <typeparam name="T">The item of items in the input collection.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
[DoesNotReturn]
public static void ThrowArgumentExceptionForIsNotEmpty<T>(string name)
internal static void ThrowArgumentExceptionForIsNotEmpty<T>(string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must not be empty");
}
Expand Down
Loading