-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Guard APIs #3131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
michael-hawker
merged 128 commits into
CommunityToolkit:master
from
Sergio0694:feature/guard-apis
Mar 15, 2020
Merged
Guard APIs #3131
Changes from 124 commits
Commits
Show all changes
128 commits
Select commit
Hold shift + click to select a range
1c79157
Initial guard APIs added
Sergio0694 0554d2f
Added EqualTo and NotEqualTo APIs
Sergio0694 6dc701f
Merge branch 'master' into feature/guard-apis
Sergio0694 018e5c4
Added more Guard APIs
Sergio0694 8d78ba3
New interval Guard APIs added
Sergio0694 0b76fb9
Added Guard APIs for IEnumerable<T> values
Sergio0694 8028741
Renamed APIs
Sergio0694 cd23275
Added Guard APIs for Stream values
Sergio0694 a54441c
Added Guard APIs for ReadOnlySpan<T> values
Sergio0694 8dee59a
Added Guard APIs for ReadOnlyMemory<T> values
Sergio0694 2d32333
Code refactoring
Sergio0694 19e3bcc
Minor code refactoring
Sergio0694 0ff1f00
Added Guard.IsBitwiseEqualTo<T> API
Sergio0694 9dd8a80
Added Guard.IsNull API
Sergio0694 f2a4500
Code refactoring and optimizations
Sergio0694 b79daa7
Code refactoring
Sergio0694 d44e633
Added Guard.HasSizeNotEqualTo<T> API
Sergio0694 0292f9d
Added Guard size API overloads for the string type
Sergio0694 073a205
Added Guard size API overloads for T[] arrays
Sergio0694 5edef16
Code refactoring
Sergio0694 1a19fea
Removed unnecessary using directives
Sergio0694 d38ad13
Added Guard reference check APIs
Sergio0694 e9108fc
Added new Guaard APIs for string values
Sergio0694 18bb2d4
Improved Guard.IsBitwiseEqualTo<T> API
Sergio0694 2d9536f
Improved Guard.IsNull APIs
Sergio0694 a927dad
Added new size APIs for copy operations
Sergio0694 56a3a18
Added new type test APIs, minor code tweaks
Sergio0694 bbd10a8
Minor bug fixes
Sergio0694 fbb5801
Added Guard APIs for Task values
Sergio0694 eba232e
Minor code tweak
Sergio0694 9071e12
Added new Guard.IsEmpty APIs
Sergio0694 edb1d41
Refactored code to remove unsafe requirement
Sergio0694 d9c83f4
Added Guard.IsInRange<T> APIs
Sergio0694 e63402b
Added missing type checks in Guard.IsBitwiseEqualTo API
Sergio0694 87056c9
Added ValueTypeExtensions.ToHexString API
Sergio0694 0d34c0a
Code refactoring
Sergio0694 497d149
Added ValueTypeExtensions tests
Sergio0694 bc0fc1b
Added general Guard tests
Sergio0694 606cbde
Bug fixes in the Guard class
Sergio0694 f29cd93
Minor speed improvements
Sergio0694 79d2dd4
Code refactoring
Sergio0694 793c769
Removed unnecessary using directives
Sergio0694 8e2f2d8
More speed improvements and API refactoring
Sergio0694 5b58e5e
Refactored/fixed some Guard APIs
Sergio0694 b664c90
More bug fixes
Sergio0694 7f65184
Added Guard tests for array APIs
Sergio0694 4304edd
Fixed the Guard.IsNotEmpty<T> array API
Sergio0694 4802936
Moved exception throwers to separate class
Sergio0694 ed5315a
Moved general Guard throwers to separate class
Sergio0694 1772a0f
Disabled warning for XML overload resolution
Sergio0694 9814d91
Moved array Guard throwers to separate class
Sergio0694 1b78344
Moved stream Guard throwers to separate class
Sergio0694 bc0dc18
Fixed some XML docs
Sergio0694 e000fe0
Moved enumerable Guard throwers to separate class
Sergio0694 21cf16a
Moved task Guard throwers to separate class
Sergio0694 c1b9c8b
Added new Guard APIs for tasks
Sergio0694 c784d4e
Moved string Guard throwers to separate class
Sergio0694 8cf87c3
Moved ReadOnlySpan<T> Guard throwers to separate class
Sergio0694 24e03f5
Added Span<T> APIs to the Guard class
Sergio0694 6f1679b
Moved ReadOnlyMemory<T> Guard throwers to separate class
Sergio0694 7e80e43
Added Memory<T> APIs to the Guard class
Sergio0694 662bb83
Minor code refactoring
Sergio0694 1c334df
Update file headers
Sergio0694 eccc2a6
Removed unnecessary methods
Sergio0694 15ef6a3
Added TypeExtensions.ToTypeString extension
Sergio0694 317fc99
Improved error messages for general Guard APIs
Sergio0694 cb1f3b0
Improved error messages for Enumerable Guard APIs
Sergio0694 23f1504
Improved error messages for stream Guard APIs
Sergio0694 920e69f
Improved error messages for array Guard APIs
Sergio0694 18e661f
Improved error messages for string Guard APIs
Sergio0694 d00e0e3
Improved error messages for task Guard APIs
Sergio0694 6aeedaa
Improved error messages for span Guard APIs
Sergio0694 acafd8a
Improved error messages for memory Guard APIs
Sergio0694 8c7757a
Improved type string for nullable types
Sergio0694 c2fd97c
Improved type string for value tuple types
Sergio0694 8facb7e
Minor performance improvement
Sergio0694 2952e23
Added numeric comparison T4 file
Sergio0694 4991a5c
Updated .gitignore to skip generated files
Sergio0694 714cf31
Moved comparison Guard APIs to separate file
Sergio0694 fa8cc56
Renamed template file, fixed incorrect XML doc
Sergio0694 effb2ed
Fixed missing blank line
Sergio0694 e2e5171
Removed unnecessary type parameters
Sergio0694 4482217
Moved enumerable Guard APIs to separate file
Sergio0694 94872b9
Code refactoring in the enumerable T4 template
Sergio0694 756c842
Renamed a file
Sergio0694 0ecef12
Added empty template for ThrowHelper.Collection
Sergio0694 e093427
Code refactoring in the T4 templates
Sergio0694 9db9cd0
Switched collection throw helpers to T4 generation
Sergio0694 f6e3248
Code refactoring
Sergio0694 deb302b
Merge pull request #7 from Sergio0694/feature/guard-apis-T4
Sergio0694 fcc3c05
Removed incorrect file header
Sergio0694 760972f
Added new Guard.IsInRangeFor API
Sergio0694 8d6cc8a
Updated .gitignore, added generated files to source control
Sergio0694 e3d245f
Added tests for Guard.IsInRangeFor
Sergio0694 d367add
Improved formatting of values in error messages
Sergio0694 6d97f33
Improved error messages
Sergio0694 ec67152
More improvements to the error messages
Sergio0694 b2c3acb
Minor code tweaks
Sergio0694 43b22f0
Added Guard.IsNotOfType APIs
Sergio0694 c8af095
Added Guard.IsNotAssignableToType APIs
Sergio0694 7adfa79
Added Guard.IsDefault<T> APIs
Sergio0694 95b9fd1
Merge branch 'master' into feature/guard-apis
Sergio0694 d4c2d05
Fixed some XML docs
Sergio0694 afd973e
Added missing [Pure] attribute
Sergio0694 96ce238
Fixed typo in a comment
Sergio0694 cb98a02
Removed unnecessary comment after code changes
Sergio0694 5f25e18
Added XML comment for the T4 service
Sergio0694 cf5785c
Added more comments to ToHexString
Sergio0694 801dc93
Suppressed an incorrect code style warning
Sergio0694 b840201
Added more tests for Guard.IsInRange
Sergio0694 818c1eb
Added Guard.IsNotInRangeFor APIs
Sergio0694 caad2f7
Added readme file for the T4 templates
Sergio0694 7134f98
Changed generated files extension to .g.cs to avoid conflicts
Sergio0694 01a7257
Added Guard.IsCloseTo and Guard.IsNotCloseTo APIs
Sergio0694 f33c984
Added tests for IsCloseTo
Sergio0694 1b0f2c9
Updated ".g.cs" extension for generated files
Sergio0694 ef189ba
Removed extra space (typo)
Sergio0694 ac44dad
More tweakes to the Guard.md file
Sergio0694 21115f6
Excluded TypeInfo.g.cs file from .ttinclude from checkout
Sergio0694 67fcd47
Added more info about target ranges for some APIs
Sergio0694 41fea84
Added IsCloseTo overloads for long type
Sergio0694 132d240
Minor code tweaks
Sergio0694 f17aacd
Added comment to describe (uint) cast range check trick
Sergio0694 949134b
Added a nore about the .g.cs files being checked in
Sergio0694 c9283d1
Merge branch 'master' into feature/guard-apis
michael-hawker de701b6
Merge branch 'master' into feature/guard-apis
Sergio0694 51b45e2
Fixed IsCloseTo tests
Sergio0694 244da99
Fixed IsNull tests
Sergio0694 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,638 changes: 1,638 additions & 0 deletions
1,638
Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.g.cs
Large diffs are not rendered by default.
Oops, something went wrong.
283 changes: 283 additions & 0 deletions
283
Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.tt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,283 @@ | ||
| // 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. | ||
| <#@include file="TypeInfo.ttinclude" #> | ||
| /* ======================== | ||
| * Auto generated file | ||
| * ===================== */ | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Runtime.CompilerServices; | ||
|
|
||
| #nullable enable | ||
|
|
||
| namespace Microsoft.Toolkit.Diagnostics | ||
| { | ||
| /// <summary> | ||
| /// Helper methods to verify conditions when running code. | ||
| /// </summary> | ||
| public static partial class Guard | ||
| { | ||
| <# | ||
| GenerateTextForItems(EnumerableTypes, item => | ||
| { | ||
| #> | ||
| /// <summary> | ||
| /// Asserts that the input <#=item.XmlType#> instance must be empty. | ||
| /// </summary> | ||
| /// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam> | ||
| /// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param> | ||
| /// <param name="name">The name of the input parameter being tested.</param> | ||
| /// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is != 0.</exception> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static void IsEmpty<T>(<#=item.Type#> <#=item.Name#>, string name) | ||
| { | ||
| if (<#=item.Name#>.<#=item.Size#> != 0) | ||
| { | ||
| ThrowHelper.ThrowArgumentExceptionForIsEmpty(<#=item.Cast#><#=item.Name#>, name); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Asserts that the input <#=item.XmlType#> instance must not be empty. | ||
| /// </summary> | ||
| /// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam> | ||
| /// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param> | ||
| /// <param name="name">The name of the input parameter being tested.</param> | ||
| /// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is == 0.</exception> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static void IsNotEmpty<T>(<#=item.Type#> <#=item.Name#>, string name) | ||
| { | ||
| if (<#=item.Name#>.<#=item.Size#> == 0) | ||
| { | ||
| <# | ||
| if (item.Type == "Span<T>") | ||
| { | ||
| #> | ||
| ThrowHelper.ThrowArgumentExceptionForIsNotEmptyWithSpan<T>(name); | ||
| <# | ||
| } | ||
| else if (item.Type == "ReadOnlySpan<T>") | ||
| { | ||
| #> | ||
| ThrowHelper.ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan<T>(name); | ||
| <# | ||
| } | ||
| else | ||
| { | ||
| #> | ||
| ThrowHelper.ThrowArgumentExceptionForIsNotEmpty<<#=item.Type#>>(name); | ||
| <# | ||
| } | ||
| #> | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Asserts that the input <#=item.XmlType#> instance must have a size of a specified value. | ||
| /// </summary> | ||
| /// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam> | ||
| /// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param> | ||
| /// <param name="size">The target size to test.</param> | ||
| /// <param name="name">The name of the input parameter being tested.</param> | ||
| /// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is != <paramref name="size"/>.</exception> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static void HasSizeEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name) | ||
| { | ||
| if (<#=item.Name#>.<#=item.Size#> != size) | ||
michael-hawker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Cast#><#=item.Name#>, size, name); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Asserts that the input <#=item.XmlType#> instance must have a size not equal to a specified value. | ||
| /// </summary> | ||
| /// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam> | ||
| /// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param> | ||
| /// <param name="size">The target size to test.</param> | ||
| /// <param name="name">The name of the input parameter being tested.</param> | ||
| /// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is == <paramref name="size"/>.</exception> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static void HasSizeNotEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name) | ||
| { | ||
| if (<#=item.Name#>.<#=item.Size#> == size) | ||
| { | ||
| ThrowHelper.ThrowArgumentExceptionForHasSizeNotEqualTo(<#=item.Cast#><#=item.Name#>, size, name); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Asserts that the input <#=item.XmlType#> instance must have a size over a specified value. | ||
| /// </summary> | ||
| /// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam> | ||
| /// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param> | ||
| /// <param name="size">The target size to test.</param> | ||
| /// <param name="name">The name of the input parameter being tested.</param> | ||
| /// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is <= <paramref name="size"/>.</exception> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static void HasSizeOver<T>(<#=item.Type#> <#=item.Name#>, int size, string name) | ||
| { | ||
| if (<#=item.Name#>.<#=item.Size#> <= size) | ||
| { | ||
| ThrowHelper.ThrowArgumentExceptionForHasSizeOver(<#=item.Cast#><#=item.Name#>, size, name); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Asserts that the input <#=item.XmlType#> instance must have a size of at least or equal to a specified value. | ||
| /// </summary> | ||
| /// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam> | ||
| /// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param> | ||
| /// <param name="size">The target size to test.</param> | ||
| /// <param name="name">The name of the input parameter being tested.</param> | ||
| /// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is < <paramref name="size"/>.</exception> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static void HasSizeAtLeast<T>(<#=item.Type#> <#=item.Name#>, int size, string name) | ||
| { | ||
| if (<#=item.Name#>.<#=item.Size#> < size) | ||
| { | ||
| ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(<#=item.Cast#><#=item.Name#>, size, name); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Asserts that the input <#=item.XmlType#> instance must have a size of less than a specified value. | ||
| /// </summary> | ||
| /// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam> | ||
| /// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param> | ||
| /// <param name="size">The target size to test.</param> | ||
| /// <param name="name">The name of the input parameter being tested.</param> | ||
| /// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is >= <paramref name="size"/>.</exception> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static void HasSizeLessThan<T>(<#=item.Type#> <#=item.Name#>, int size, string name) | ||
| { | ||
| if (<#=item.Name#>.<#=item.Size#> >= size) | ||
| { | ||
| ThrowHelper.ThrowArgumentExceptionForHasSizeLessThan(<#=item.Cast#><#=item.Name#>, size, name); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Asserts that the input <#=item.XmlType#> instance must have a size of less than or equal to a specified value. | ||
| /// </summary> | ||
| /// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam> | ||
| /// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to check the size for.</param> | ||
| /// <param name="size">The target size to test.</param> | ||
| /// <param name="name">The name of the input parameter being tested.</param> | ||
| /// <exception cref="ArgumentException">Thrown if the size of <paramref name="<#=item.Name#>"/> is > <paramref name="size"/>.</exception> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static void HasSizeLessThanOrEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name) | ||
| { | ||
| if (<#=item.Name#>.<#=item.Size#> > size) | ||
| { | ||
| ThrowHelper.ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(<#=item.Cast#><#=item.Name#>, size, name); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Asserts that the source <#=item.XmlType#> instance must have the same size of a destination <#=item.XmlType#> instance. | ||
| /// </summary> | ||
| /// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam> | ||
| /// <param name="source">The source <#=item.XmlType#> instance to check the size for.</param> | ||
| /// <param name="destination">The destination <#=item.XmlType#> instance to check the size for.</param> | ||
| /// <param name="name">The name of the input parameter being tested.</param> | ||
| /// <exception cref="ArgumentException">Thrown if the size of <paramref name="source"/> is != the one of <paramref name="destination"/>.</exception> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static void HasSizeEqualTo<T>(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) | ||
| { | ||
| if (source.<#=item.Size#> != destination.<#=item.Size#>) | ||
| { | ||
| <# | ||
| if (item.HasCountProperty) | ||
| { | ||
| #> | ||
| ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Cast#>source, destination.<#=item.Size#>, name); | ||
| <# | ||
| } | ||
| else | ||
| { | ||
| #> | ||
| ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(source, <#=item.Cast#>destination, name); | ||
| <# | ||
| } | ||
| #> | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Asserts that the source <#=item.XmlType#> instance must have a size of less than or equal to that of a destination <#=item.XmlType#> instance. | ||
| /// </summary> | ||
| /// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam> | ||
| /// <param name="source">The source <#=item.XmlType#> instance to check the size for.</param> | ||
| /// <param name="destination">The destination <#=item.XmlType#> instance to check the size for.</param> | ||
| /// <param name="name">The name of the input parameter being tested.</param> | ||
| /// <exception cref="ArgumentException">Thrown if the size of <paramref name="source"/> is > the one of <paramref name="destination"/>.</exception> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static void HasSizeLessThanOrEqualTo<T>(<#=item.Type#> source, <#=item.DestinationType#> destination, string name) | ||
| { | ||
| if (source.<#=item.Size#> > destination.<#=item.Size#>) | ||
| { | ||
| <# | ||
| if (item.HasCountProperty) | ||
| { | ||
| #> | ||
| ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(<#=item.Cast#>source, destination.<#=item.Size#>, name); | ||
| <# | ||
| } | ||
| else | ||
| { | ||
| #> | ||
| ThrowHelper.ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(source, <#=item.Cast#>destination, name); | ||
| <# | ||
| } | ||
| #> | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Asserts that the input index is valid for a given <#=item.XmlType#> instance. | ||
| /// </summary> | ||
| /// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam> | ||
| /// <param name="index">The input index to be used to access <paramref name="<#=item.Name#>"/>.</param> | ||
| /// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to use to validate <paramref name="index"/>.</param> | ||
| /// <param name="name">The name of the input parameter being tested.</param> | ||
| /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is not valid to access <paramref name="<#=item.Name#>"/>.</exception> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static void IsInRangeFor<T>(int index, <#=item.Type#> <#=item.Name#>, string name) | ||
| { | ||
| <# | ||
| /* Here we're leveraging the fact that signed integers are represented | ||
| * in 2-complement to perform the bounds check with a single compare operation. | ||
| * This is the same trick used throughout CoreCLR as well. | ||
| * For more info and code sample, see the original conversation here: | ||
| * https://github.com/windows-toolkit/WindowsCommunityToolkit/pull/3131#discussion_r390682835 */ | ||
| #> | ||
| if ((uint)index >= (uint)<#=item.Name#>.<#=item.Size#>) | ||
michael-hawker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsInRangeFor(index, <#=item.Cast#><#=item.Name#>, name); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Asserts that the input index is not valid for a given <#=item.XmlType#> instance. | ||
| /// </summary> | ||
| /// <typeparam name="T">The item of items in the input <#=item.XmlType#> instance.</typeparam> | ||
| /// <param name="index">The input index to be used to access <paramref name="<#=item.Name#>"/>.</param> | ||
| /// <param name="<#=item.Name#>">The input <#=item.XmlType#> instance to use to validate <paramref name="index"/>.</param> | ||
| /// <param name="name">The name of the input parameter being tested.</param> | ||
| /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is valid to access <paramref name="<#=item.Name#>"/>.</exception> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static void IsNotInRangeFor<T>(int index, <#=item.Type#> <#=item.Name#>, string name) | ||
| { | ||
| if ((uint)index < (uint)<#=item.Name#>.<#=item.Size#>) | ||
| { | ||
| ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(index, <#=item.Cast#><#=item.Name#>, name); | ||
| } | ||
| } | ||
| <# | ||
| }); | ||
| #> | ||
| } | ||
Sergio0694 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.