Guard APIs for .NET Standard 2.1 (#3167)

* Initial guard APIs added

* Added EqualTo and NotEqualTo APIs

* Added more Guard APIs

* New interval Guard APIs added

* Added Guard APIs for IEnumerable<T> values

* Renamed APIs

* Added Guard APIs for Stream values

* Added Guard APIs for ReadOnlySpan<T> values

* Added Guard APIs for ReadOnlyMemory<T> values

* Code refactoring

* Minor code refactoring

* Added Guard.IsBitwiseEqualTo<T> API

* Added Guard.IsNull API

* Code refactoring and optimizations

* Code refactoring

* Added Guard.HasSizeNotEqualTo<T> API

* Added Guard size API overloads for the string type

* Added Guard size API overloads for T[] arrays

* Code refactoring

* Removed unnecessary using directives

* Added Guard reference check APIs

* Added new Guaard APIs for string values

* Improved Guard.IsBitwiseEqualTo<T> API

* Improved Guard.IsNull APIs

* Added new size APIs for copy operations

* Added new type test APIs, minor code tweaks

* Minor bug fixes

* Added Guard APIs for Task values

* Minor code tweak

* Added new Guard.IsEmpty APIs

* Refactored code to remove unsafe requirement

* Added Guard.IsInRange<T> APIs

* Added missing type checks in Guard.IsBitwiseEqualTo API

* Added ValueTypeExtensions.ToHexString API

* Code refactoring

* Added ValueTypeExtensions tests

* Added general Guard tests

* Bug fixes in the Guard class

* Minor speed improvements

* Code refactoring

* Removed unnecessary using directives

* More speed improvements and API refactoring

* Refactored/fixed some Guard APIs

* More bug fixes

* Added Guard tests for array APIs

* Fixed the Guard.IsNotEmpty<T> array API

* Moved exception throwers to separate class

* Moved general Guard throwers to separate class

* Disabled warning for XML overload resolution

* Moved array Guard throwers to separate class

* Moved stream Guard throwers to separate class

* Fixed some XML docs

* Moved enumerable Guard throwers to separate class

* Moved task Guard throwers to separate class

* Added new Guard APIs for tasks

* Moved string Guard throwers to separate class

* Moved ReadOnlySpan<T> Guard throwers to separate class

* Added Span<T> APIs to the Guard class

* Moved ReadOnlyMemory<T> Guard throwers to separate class

* Added Memory<T> APIs to the Guard class

* Minor code refactoring

* Update file headers

* Removed unnecessary methods

* Added TypeExtensions.ToTypeString extension

* Improved error messages for general Guard APIs

* Improved error messages for Enumerable Guard APIs

* Improved error messages for stream Guard APIs

* Improved error messages for array Guard APIs

* Improved error messages for string Guard APIs

* Improved error messages for task Guard APIs

* Improved error messages for span Guard APIs

* Improved error messages for memory Guard APIs

* Improved type string for nullable types

* Improved type string for value tuple types

* Minor performance improvement

* Added numeric comparison T4 file

* Updated .gitignore to skip generated files

* Moved comparison Guard APIs to separate file

* Renamed template file, fixed incorrect XML doc

* Fixed missing blank line

* Removed unnecessary type parameters

* Moved enumerable Guard APIs to separate file

* Code refactoring in the enumerable T4 template

* Renamed a file

* Added empty template for ThrowHelper.Collection

* Code refactoring in the T4 templates

* Switched collection throw helpers to T4 generation

* Code refactoring

* Removed incorrect file header

* Added new Guard.IsInRangeFor API

* Updated .gitignore, added generated files to source control

* Added tests for Guard.IsInRangeFor

* Improved formatting of values in error messages

* Improved error messages

* More improvements to the error messages

* Minor code tweaks

* Added Guard.IsNotOfType APIs

* Added Guard.IsNotAssignableToType APIs

* Added Guard.IsDefault<T> APIs

* Fixed some XML docs

* Added missing [Pure] attribute

* Fixed typo in a comment

* Removed unnecessary comment after code changes

* Added XML comment for the T4 service

* Added more comments to ToHexString

* Suppressed an incorrect code style warning

* Added more tests for Guard.IsInRange

* Added Guard.IsNotInRangeFor APIs

* Added readme file for the T4 templates

* Changed generated files extension to .g.cs to avoid conflicts

* Added Guard.IsCloseTo and Guard.IsNotCloseTo APIs

* Added tests for IsCloseTo

* Updated ".g.cs" extension for generated files

Co-Authored-By: Michael Hawker MSFT (XAML Llama) <michael.hawker@outlook.com>

* Removed extra space (typo)

Co-Authored-By: Michael Hawker MSFT (XAML Llama) <michael.hawker@outlook.com>

* More tweakes to the Guard.md file

* Excluded TypeInfo.g.cs file from .ttinclude from checkout

* Added more info about target ranges for some APIs

* Added IsCloseTo overloads for long type

* Minor code tweaks

* Added comment to describe (uint) cast range check trick

* Added a nore about the .g.cs files being checked in

* Added .NET Standard 2.1 target, adjusted imported packages

* Added [NotNull] attributes when needed

* Added flow attributes to bool Guard APIs

* Added missing Guard APIs for the string type

* Added shared main unit test project

* Removed duplicate files from UWP unit test project

* Refactored UWP unit tests project (can't be in same folder as .shproj)

* Moved markdown tests back into UWP project

* Added UnitTests.NetCore project

* Fixed some styling issues in test projects

* Added .editorconfig file to UniTests.NetCore project too

* Moved .editorconfig file to Shared project folder

* Removed NetCore Tests compilation for Native Configuration.

* Update Windows Community Toolkit.sln

* Updated multiline comments style

* Renamed some Guard APIs

* Fixed collections tests, moved to shared project

* Removed unnecessary [SuppressMessage] attributes

* Added internal [NotNull] and [DoesNotReturnIf] attributes

* Removed build warnings

* Removed leftover compiler directives

* Added Guard.IsTrue/False overloads with custom message

* Fixed test file location after merge

* Fixed Span<T> and Unsafe package references

Co-authored-by: Michael Hawker MSFT (XAML Llama) <michael.hawker@outlook.com>
Co-authored-by: Alexandre Zollinger Chohfi <alzollin@microsoft.com>
Co-authored-by: Alexandre Zollinger Chohfi <chohfi@outlook.com>
Co-authored-by: Michael Hawker MSFT (XAML Llama) <24302614+michael-hawker@users.noreply.github.com>
This commit is contained in:
Sergio Pedri 2020-05-15 23:14:14 +02:00 коммит произвёл GitHub
Родитель 01075ff459
Коммит 3910c2ed62
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
105 изменённых файлов: 566 добавлений и 225 удалений

Просмотреть файл

@ -11,7 +11,7 @@ using System.Text.RegularExpressions;
using Microsoft.Toolkit.Parsers.Core;
using Microsoft.Toolkit.Parsers.Markdown.Helpers;
[assembly: InternalsVisibleTo("UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010041753af735ae6140c9508567666c51c6ab929806adb0d210694b30ab142a060237bc741f9682e7d8d4310364b4bba4ee89cc9d3d5ce7e5583587e8ea44dca09977996582875e71fb54fa7b170798d853d5d8010b07219633bdb761d01ac924da44576d6180cdceae537973982bb461c541541d58417a3794e34f45e6f2d129e2")]
[assembly: InternalsVisibleTo("UnitTests.UWP, PublicKey=002400000480000094000000060200000024000052534131000400000100010041753af735ae6140c9508567666c51c6ab929806adb0d210694b30ab142a060237bc741f9682e7d8d4310364b4bba4ee89cc9d3d5ce7e5583587e8ea44dca09977996582875e71fb54fa7b170798d853d5d8010b07219633bdb761d01ac924da44576d6180cdceae537973982bb461c541541d58417a3794e34f45e6f2d129e2")]
namespace Microsoft.Toolkit.Parsers.Markdown.Blocks
{

Просмотреть файл

@ -8,5 +8,5 @@ using System.Runtime.CompilerServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: InternalsVisibleTo("UnitTests")]
[assembly: InternalsVisibleTo("UnitTests.UWP")]
[assembly: NeutralResourcesLanguage("en-US")]

Просмотреть файл

@ -8,5 +8,5 @@ using System.Runtime.CompilerServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: InternalsVisibleTo("UnitTests")]
[assembly: InternalsVisibleTo("UnitTests.UWP")]
[assembly: NeutralResourcesLanguage("en-US")]

Просмотреть файл

@ -0,0 +1,36 @@
// 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.
#if !NETSTANDARD2_1
namespace System.Diagnostics.CodeAnalysis
{
/// <summary>
/// Specifies that a given <see cref="ParameterValue"/> also indicates
/// whether the method will not return (eg. throw an exception).
/// </summary>
/// <remarks>Internal copy of the .NET Standard 2.1 attribute.</remarks>
[AttributeUsage(AttributeTargets.Parameter)]
internal sealed class DoesNotReturnIfAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="DoesNotReturnIfAttribute"/> class.
/// </summary>
/// <param name="parameterValue">
/// The condition parameter value. Code after the method will be considered unreachable
/// by diagnostics if the argument to the associated parameter matches this value.
/// </param>
public DoesNotReturnIfAttribute(bool parameterValue)
{
ParameterValue = parameterValue;
}
/// <summary>
/// Gets a value indicating whether the parameter value should be <see langword="true"/>.
/// </summary>
public bool ParameterValue { get; }
}
}
#endif

Просмотреть файл

@ -0,0 +1,26 @@
// 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.
#if !NETSTANDARD2_1
namespace System.Diagnostics.CodeAnalysis
{
/// <summary>
/// Specifies that an output will not be <see langword="null"/> even if the corresponding type allows it.
/// Specifies that an input argument was not <see langword="null"/> when the call returns.
/// </summary>
/// <remarks>Internal copy of the .NET Standard 2.1 attribute.</remarks>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue)]
internal sealed class NotNullAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="NotNullAttribute"/> class.
/// </summary>
public NotNullAttribute()
{
}
}
}
#endif

Просмотреть файл

@ -1,10 +1,9 @@
// 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.
/* ========================
* Auto generated file
* ===================== */
// =====================
// Auto generated file
// =====================
using System;
using System.Collections.Generic;
@ -94,11 +93,11 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="span"/> is &lt;= <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeOver<T>(Span<T> span, int size, string name)
public static void HasSizeGreaterThan<T>(Span<T> span, int size, string name)
{
if (span.Length <= size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeOver(span, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(span, size, name);
}
}
@ -111,11 +110,11 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="span"/> is &lt; <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeAtLeast<T>(Span<T> span, int size, string name)
public static void HasSizeGreaterThanOrEqualTo<T>(Span<T> span, int size, string name)
{
if (span.Length < size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(span, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(span, size, name);
}
}
@ -296,11 +295,11 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="span"/> is &lt;= <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeOver<T>(ReadOnlySpan<T> span, int size, string name)
public static void HasSizeGreaterThan<T>(ReadOnlySpan<T> span, int size, string name)
{
if (span.Length <= size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeOver(span, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(span, size, name);
}
}
@ -313,11 +312,11 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="span"/> is &lt; <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeAtLeast<T>(ReadOnlySpan<T> span, int size, string name)
public static void HasSizeGreaterThanOrEqualTo<T>(ReadOnlySpan<T> span, int size, string name)
{
if (span.Length < size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(span, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(span, size, name);
}
}
@ -498,11 +497,11 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="memory"/> is &lt;= <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeOver<T>(Memory<T> memory, int size, string name)
public static void HasSizeGreaterThan<T>(Memory<T> memory, int size, string name)
{
if (memory.Length <= size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeOver(memory, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(memory, size, name);
}
}
@ -515,11 +514,11 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="memory"/> is &lt; <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeAtLeast<T>(Memory<T> memory, int size, string name)
public static void HasSizeGreaterThanOrEqualTo<T>(Memory<T> memory, int size, string name)
{
if (memory.Length < size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(memory, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(memory, size, name);
}
}
@ -700,11 +699,11 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="memory"/> is &lt;= <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeOver<T>(ReadOnlyMemory<T> memory, int size, string name)
public static void HasSizeGreaterThan<T>(ReadOnlyMemory<T> memory, int size, string name)
{
if (memory.Length <= size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeOver(memory, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(memory, size, name);
}
}
@ -717,11 +716,11 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="memory"/> is &lt; <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeAtLeast<T>(ReadOnlyMemory<T> memory, int size, string name)
public static void HasSizeGreaterThanOrEqualTo<T>(ReadOnlyMemory<T> memory, int size, string name)
{
if (memory.Length < size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(memory, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(memory, size, name);
}
}
@ -902,11 +901,11 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="array"/> is &lt;= <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeOver<T>(T[] array, int size, string name)
public static void HasSizeGreaterThan<T>(T[] array, int size, string name)
{
if (array.Length <= size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeOver(array, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(array, size, name);
}
}
@ -919,11 +918,11 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="array"/> is &lt; <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeAtLeast<T>(T[] array, int size, string name)
public static void HasSizeGreaterThanOrEqualTo<T>(T[] array, int size, string name)
{
if (array.Length < size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(array, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(array, size, name);
}
}
@ -1104,11 +1103,11 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="list"/> is &lt;= <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeOver<T>(List<T> list, int size, string name)
public static void HasSizeGreaterThan<T>(List<T> list, int size, string name)
{
if (list.Count <= size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeOver((ICollection<T>)list, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan((ICollection<T>)list, size, name);
}
}
@ -1121,11 +1120,11 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="list"/> is &lt; <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeAtLeast<T>(List<T> list, int size, string name)
public static void HasSizeGreaterThanOrEqualTo<T>(List<T> list, int size, string name)
{
if (list.Count < size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast((ICollection<T>)list, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo((ICollection<T>)list, size, name);
}
}
@ -1306,11 +1305,11 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="collection"/> is &lt;= <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeOver<T>(ICollection<T> collection, int size, string name)
public static void HasSizeGreaterThan<T>(ICollection<T> collection, int size, string name)
{
if (collection.Count <= size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeOver(collection, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(collection, size, name);
}
}
@ -1323,11 +1322,11 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="collection"/> is &lt; <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeAtLeast<T>(ICollection<T> collection, int size, string name)
public static void HasSizeGreaterThanOrEqualTo<T>(ICollection<T> collection, int size, string name)
{
if (collection.Count < size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(collection, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(collection, size, name);
}
}
@ -1508,11 +1507,11 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="collection"/> is &lt;= <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeOver<T>(IReadOnlyCollection<T> collection, int size, string name)
public static void HasSizeGreaterThan<T>(IReadOnlyCollection<T> collection, int size, string name)
{
if (collection.Count <= size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeOver(collection, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(collection, size, name);
}
}
@ -1525,11 +1524,11 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="collection"/> is &lt; <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeAtLeast<T>(IReadOnlyCollection<T> collection, int size, string name)
public static void HasSizeGreaterThanOrEqualTo<T>(IReadOnlyCollection<T> collection, int size, string name)
{
if (collection.Count < size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(collection, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(collection, size, name);
}
}

Просмотреть файл

@ -2,10 +2,6 @@
// 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;
@ -117,11 +113,11 @@ GenerateTextForItems(EnumerableTypes, item =>
/// <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 &lt;= <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeOver<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
public static void HasSizeGreaterThan<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
{
if (<#=item.Name#>.<#=item.Size#> <= size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeOver(<#=item.Cast#><#=item.Name#>, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(<#=item.Cast#><#=item.Name#>, size, name);
}
}
@ -134,11 +130,11 @@ GenerateTextForItems(EnumerableTypes, item =>
/// <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 &lt; <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeAtLeast<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
public static void HasSizeGreaterThanOrEqualTo<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
{
if (<#=item.Name#>.<#=item.Size#> < size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(<#=item.Cast#><#=item.Name#>, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(<#=item.Cast#><#=item.Name#>, size, name);
}
}
@ -248,11 +244,11 @@ GenerateTextForItems(EnumerableTypes, item =>
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 */
// 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#>)
{

Просмотреть файл

@ -1,10 +1,9 @@
// 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.
/* ========================
* Auto generated file
* ===================== */
// =====================
// Auto generated file
// =====================
using System;
using System.Runtime.CompilerServices;

Просмотреть файл

@ -2,10 +2,6 @@
// 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.Runtime.CompilerServices;

Просмотреть файл

@ -1,14 +1,12 @@
// 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.
/* ========================
* Auto generated file
* ===================== */
// =====================
// Auto generated file
// =====================
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@ -19,7 +17,6 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Helper methods to throw exceptions
/// </summary>
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")]
internal static partial class ThrowHelper
{
/// <summary>
@ -50,19 +47,19 @@ namespace Microsoft.Toolkit.Diagnostics
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeOver{T}(T[],int,string)"/> (or an overload) fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeOver<T>(Span<T> span, int size, string name)
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(Span<T> span, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span<T>).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}");
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeAtLeast{T}(T[],int,string)"/> (or an overload) fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeAtLeast<T>(Span<T> span, int size, string name)
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(Span<T> span, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span<T>).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}");
}
@ -149,19 +146,19 @@ namespace Microsoft.Toolkit.Diagnostics
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeOver{T}(T[],int,string)"/> (or an overload) fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeOver<T>(ReadOnlySpan<T> span, int size, string name)
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(ReadOnlySpan<T> span, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan<T>).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}");
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeAtLeast{T}(T[],int,string)"/> (or an overload) fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeAtLeast<T>(ReadOnlySpan<T> span, int size, string name)
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(ReadOnlySpan<T> span, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan<T>).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}");
}
@ -248,19 +245,19 @@ namespace Microsoft.Toolkit.Diagnostics
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeOver{T}(T[],int,string)"/> (or an overload) fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeOver<T>(Memory<T> memory, int size, string name)
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(Memory<T> memory, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory<T>).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}");
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeAtLeast{T}(T[],int,string)"/> (or an overload) fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeAtLeast<T>(Memory<T> memory, int size, string name)
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(Memory<T> memory, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory<T>).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}");
}
@ -347,19 +344,19 @@ namespace Microsoft.Toolkit.Diagnostics
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeOver{T}(T[],int,string)"/> (or an overload) fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeOver<T>(ReadOnlyMemory<T> memory, int size, string name)
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(ReadOnlyMemory<T> memory, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory<T>).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}");
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeAtLeast{T}(T[],int,string)"/> (or an overload) fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeAtLeast<T>(ReadOnlyMemory<T> memory, int size, string name)
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(ReadOnlyMemory<T> memory, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory<T>).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}");
}
@ -446,19 +443,19 @@ namespace Microsoft.Toolkit.Diagnostics
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeOver{T}(T[],int,string)"/> (or an overload) fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeOver<T>(T[] array, int size, string name)
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(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()}");
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeAtLeast{T}(T[],int,string)"/> (or an overload) fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeAtLeast<T>(T[] array, int size, string name)
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(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()}");
}
@ -545,19 +542,19 @@ namespace Microsoft.Toolkit.Diagnostics
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeOver{T}(T[],int,string)"/> (or an overload) fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeOver<T>(List<T> list, int size, string name)
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(List<T> list, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List<T>).ToTypeString()}) must have a size over {size}, had a size of {list.Count.ToAssertString()}");
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeAtLeast{T}(T[],int,string)"/> (or an overload) fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeAtLeast<T>(List<T> list, int size, string name)
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(List<T> list, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List<T>).ToTypeString()}) must have a size of at least {size}, had a size of {list.Count.ToAssertString()}");
}
@ -644,19 +641,19 @@ namespace Microsoft.Toolkit.Diagnostics
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeOver{T}(T[],int,string)"/> (or an overload) fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeOver<T>(ICollection<T> collection, int size, string name)
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(ICollection<T> collection, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection<T>).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}");
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeAtLeast{T}(T[],int,string)"/> (or an overload) fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeAtLeast<T>(ICollection<T> collection, int size, string name)
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(ICollection<T> collection, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection<T>).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}");
}
@ -743,19 +740,19 @@ namespace Microsoft.Toolkit.Diagnostics
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeOver{T}(T[],int,string)"/> (or an overload) fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeOver<T>(IReadOnlyCollection<T> collection, int size, string name)
public static void ThrowArgumentExceptionForHasSizeGreaterThan<T>(IReadOnlyCollection<T> collection, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection<T>).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}");
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeAtLeast{T}(T[],int,string)"/> (or an overload) fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeAtLeast<T>(IReadOnlyCollection<T> collection, int size, string name)
public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo<T>(IReadOnlyCollection<T> collection, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection<T>).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}");
}

Просмотреть файл

@ -2,13 +2,8 @@
// 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.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@ -19,7 +14,6 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Helper methods to throw exceptions
/// </summary>
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")]
internal static partial class ThrowHelper
{
<#
@ -54,19 +48,19 @@ GenerateTextForItems(EnumerableTypes, item =>
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeOver{T}(T[],int,string)"/> (or an overload) fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeOver<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
public 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()}");
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeAtLeast{T}(T[],int,string)"/> (or an overload) fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo{T}(T[],int,string)"/> (or an overload) fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeAtLeast<T>(<#=item.Type#> <#=item.Name#>, int size, string name)
public 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()}");
}

Просмотреть файл

@ -2,6 +2,9 @@
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".g.cs"#>
// =====================
// Auto generated file
// =====================
<#+
/// <summary>
/// A model representing the info on an enumerable type

Просмотреть файл

@ -98,11 +98,11 @@ namespace Microsoft.Toolkit.Diagnostics
public static void IsBitwiseEqualTo<T>(T value, T target, string name)
where T : unmanaged
{
/* Include some fast paths if the input type is of size 1, 2, 4 or 8.
* In those cases, just reinterpret the bytes as values of an integer type,
* and compare them directly, which is much faster than having a loop over each byte.
* The conditional branches below are known at compile time by the JIT compiler,
* so that only the right one will actually be translated into native code. */
// Include some fast paths if the input type is of size 1, 2, 4 or 8.
// In those cases, just reinterpret the bytes as values of an integer type,
// and compare them directly, which is much faster than having a loop over each byte.
// The conditional branches below are known at compile time by the JIT compiler,
// so that only the right one will actually be translated into native code.
if (typeof(T) == typeof(byte) ||
typeof(T) == typeof(sbyte) ||
typeof(T) == typeof(bool))

Просмотреть файл

@ -25,17 +25,17 @@ namespace Microsoft.Toolkit.Diagnostics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsCloseTo(int value, int target, uint delta, string name)
{
/* Cast to long before calculating the difference to avoid overflows
* when the values are at the two extremes of the supported range.
* Then cast to double to calculate the absolute value: this allows
* the JIT compiler to use AVX instructions on X64 CPUs instead of
* conditional jumps, which results in more efficient assembly code.
* The IEEE 754 specs guarantees that a 32 bit integer value can
* be stored within a double precision floating point value with
* no loss of precision, so the result will always be correct here.
* The difference is then cast to uint as that's the maximum possible
* value it can have, and comparing two 32 bit integer values
* results in shorter and slightly faster code than using doubles. */
// Cast to long before calculating the difference to avoid overflows
// when the values are at the two extremes of the supported range.
// Then cast to double to calculate the absolute value: this allows
// the JIT compiler to use AVX instructions on X64 CPUs instead of
// conditional jumps, which results in more efficient assembly code.
// The IEEE 754 specs guarantees that a 32 bit integer value can
// be stored within a double precision floating point value with
// no loss of precision, so the result will always be correct here.
// The difference is then cast to uint as that's the maximum possible
// value it can have, and comparing two 32 bit integer values
// results in shorter and slightly faster code than using doubles.
if ((uint)Math.Abs((double)((long)value - target)) > delta)
{
ThrowHelper.ThrowArgumentExceptionForIsCloseTo(value, target, delta, name);
@ -70,8 +70,8 @@ namespace Microsoft.Toolkit.Diagnostics
[MethodImpl(MethodImplOptions.NoInlining)]
public static void IsCloseTo(long value, long target, ulong delta, string name)
{
/* This method and the one below are not inlined because
* using the decimal type results in quite a bit of code. */
// This method and the one below are not inlined because
// using the decimal type results in quite a bit of code.
if ((ulong)Math.Abs((decimal)value - target) > delta)
{
ThrowHelper.ThrowArgumentExceptionForIsCloseTo(value, target, delta, name);

Просмотреть файл

@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
#nullable enable
@ -36,7 +37,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if <paramref name="text"/> is <see langword="null"/> or empty.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsNotNullOrEmpty(string? text, string name)
public static void IsNotNullOrEmpty([NotNull] string? text, string name)
{
if (string.IsNullOrEmpty(text))
{
@ -66,7 +67,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if <paramref name="text"/> is <see langword="null"/> or whitespace.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsNotNullOrWhitespace(string? text, string name)
public static void IsNotNullOrWhitespace([NotNull] string? text, string name)
{
if (string.IsNullOrWhiteSpace(text))
{
@ -174,11 +175,11 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="text"/> is &lt;= <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeOver(string text, int size, string name)
public static void HasSizeGreaterThan(string text, int size, string name)
{
if (text.Length <= size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeOver(text, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(text, size, name);
}
}
@ -190,11 +191,11 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if the size of <paramref name="text"/> is &lt; <paramref name="size"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeAtLeast(string text, int size, string name)
public static void HasSizeGreaterThanOrEqualTo(string text, int size, string name)
{
if (text.Length < size)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(text, size, name);
ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(text, size, name);
}
}
@ -229,5 +230,71 @@ namespace Microsoft.Toolkit.Diagnostics
ThrowHelper.ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(text, size, name);
}
}
/// <summary>
/// Asserts that the source <see cref="string"/> instance must have the same size of a destination <see cref="string"/> instance.
/// </summary>
/// <param name="source">The source <see cref="string"/> instance to check the size for.</param>
/// <param name="destination">The destination <see cref="string"/> 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>
/// <remarks>The <see cref="string"/> type is immutable, but the name of this API is kept for consistency with the other overloads.</remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeEqualTo(string source, string destination, string name)
{
if (source.Length != destination.Length)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(source, destination, name);
}
}
/// <summary>
/// Asserts that the source <see cref="string"/> instance must have a size of less than or equal to that of a destination <see cref="string"/> instance.
/// </summary>
/// <param name="source">The source <see cref="string"/> instance to check the size for.</param>
/// <param name="destination">The destination <see cref="string"/> 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>
/// <remarks>The <see cref="string"/> type is immutable, but the name of this API is kept for consistency with the other overloads.</remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void HasSizeLessThanOrEqualTo(string source, string destination, string name)
{
if (source.Length > destination.Length)
{
ThrowHelper.ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(source, destination, name);
}
}
/// <summary>
/// Asserts that the input index is valid for a given <see cref="string"/> instance.
/// </summary>
/// <param name="index">The input index to be used to access <paramref name="text"/>.</param>
/// <param name="text">The input <see cref="string"/> 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="text"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsInRangeFor(int index, string text, string name)
{
if ((uint)index >= (uint)text.Length)
{
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsInRangeFor(index, text, name);
}
}
/// <summary>
/// Asserts that the input index is not valid for a given <see cref="string"/> instance.
/// </summary>
/// <param name="index">The input index to be used to access <paramref name="text"/>.</param>
/// <param name="text">The input <see cref="string"/> 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="text"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsNotInRangeFor(int index, string text, string name)
{
if ((uint)index < (uint)text.Length)
{
ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(index, text, name);
}
}
}
}

Просмотреть файл

@ -25,7 +25,6 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is not <see langword="null"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1119", Justification = "Negated pattern match expression")]
public static void IsNull<T>(T? value, string name)
where T : class
{
@ -44,7 +43,6 @@ namespace Microsoft.Toolkit.Diagnostics
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is not <see langword="null"/>.</exception>
/// <remarks>The method is generic to avoid boxing the parameters, if they are value types.</remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1119", Justification = "Negated pattern match expression")]
public static void IsNull<T>(T? value, string name)
where T : struct
{
@ -62,7 +60,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is <see langword="null"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsNotNull<T>(T? value, string name)
public static void IsNotNull<T>([NotNull] T? value, string name)
where T : class
{
if (value is null)
@ -80,7 +78,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <exception cref="ArgumentNullException">Thrown if <paramref name="value"/> is <see langword="null"/>.</exception>
/// <remarks>The method is generic to avoid boxing the parameters, if they are value types.</remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsNotNull<T>(T? value, string name)
public static void IsNotNull<T>([NotNull] T? value, string name)
where T : struct
{
if (value is null)
@ -262,7 +260,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is <see langword="false"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsTrue(bool value, string name)
public static void IsTrue([DoesNotReturnIf(false)] bool value, string name)
{
if (!value)
{
@ -270,6 +268,22 @@ namespace Microsoft.Toolkit.Diagnostics
}
}
/// <summary>
/// Asserts that the input value must be <see langword="true"/>.
/// </summary>
/// <param name="value">The input <see cref="bool"/> to test.</param>
/// <param name="name">The name of the input parameter being tested.</param>
/// <param name="message">A message to display if <paramref name="value"/> is <see langword="false"/>.</param>
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is <see langword="false"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsTrue([DoesNotReturnIf(false)] bool value, string name, string message)
{
if (!value)
{
ThrowHelper.ThrowArgumentExceptionForIsTrue(name, message);
}
}
/// <summary>
/// Asserts that the input value must be <see langword="false"/>.
/// </summary>
@ -277,12 +291,28 @@ namespace Microsoft.Toolkit.Diagnostics
/// <param name="name">The name of the input parameter being tested.</param>
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is <see langword="true"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsFalse(bool value, string name)
public static void IsFalse([DoesNotReturnIf(true)] bool value, string name)
{
if (value)
{
ThrowHelper.ThrowArgumentExceptionForIsFalse(name);
}
}
/// <summary>
/// Asserts that the input value must be <see langword="false"/>.
/// </summary>
/// <param name="value">The input <see cref="bool"/> to test.</param>
/// <param name="name">The name of the input parameter being tested.</param>
/// <param name="message">A message to display if <paramref name="value"/> is <see langword="true"/>.</param>
/// <exception cref="ArgumentException">Thrown if <paramref name="value"/> is <see langword="true"/>.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsFalse([DoesNotReturnIf(true)] bool value, string name, string message)
{
if (value)
{
ThrowHelper.ThrowArgumentExceptionForIsFalse(name, message);
}
}
}
}

Просмотреть файл

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@ -14,12 +13,12 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Helper methods to throw exceptions
/// </summary>
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")]
internal static partial class ThrowHelper
{
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotEmpty{T}(Span{T},string)"/> fails.
/// </summary>
/// <typeparam name="T">The item of items in the input <see cref="Span{T}"/> instance.</typeparam>
/// <remarks>This method is needed because <see cref="Span{T}"/> can't be used as a generic type parameter.</remarks>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsNotEmptyWithSpan<T>(string name)
@ -30,7 +29,8 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotEmpty{T}(ReadOnlySpan{T},string)"/> fails.
/// </summary>
/// <remarks>This method is needed because <see cref="Span{T}"/> can't be used as a generic type parameter.</remarks>
/// <typeparam name="T">The item of items in the input <see cref="ReadOnlySpan{T}"/> instance.</typeparam>
/// <remarks>This method is needed because <see cref="ReadOnlySpan{T}"/> can't be used as a generic type parameter.</remarks>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan<T>(string name)
{
@ -40,6 +40,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotEmpty{T}(T[],string)"/> (or an overload) fails.
/// </summary>
/// <typeparam name="T">The item of items in the input collection.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsNotEmpty<T>(string name)
{

Просмотреть файл

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@ -14,12 +13,12 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Helper methods to throw exceptions
/// </summary>
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")]
internal static partial class ThrowHelper
{
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsDefault{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of <see langword="struct"/> value type being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsDefault<T>(T value, string name)
where T : struct
@ -30,6 +29,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotDefault{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of <see langword="struct"/> value type being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsNotDefault<T>(string name)
where T : struct
@ -40,6 +40,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsEqualTo{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsEqualTo<T>(T value, T target, string name)
{
@ -49,6 +50,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotEqualTo{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsNotEqualTo<T>(T value, T target, string name)
{
@ -58,6 +60,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsLessThan{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsLessThan<T>(T value, T maximum, string name)
{
@ -67,6 +70,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsLessThanOrEqualTo{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo<T>(T value, T maximum, string name)
{
@ -76,6 +80,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsGreaterThan{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan<T>(T value, T minimum, string name)
{
@ -85,6 +90,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsGreaterThanOrEqualTo{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo<T>(T value, T minimum, string name)
{
@ -94,6 +100,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsInRange{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsInRange<T>(T value, T minimum, T maximum, string name)
{
@ -103,6 +110,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsInRange{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRange<T>(T value, T minimum, T maximum, string name)
{
@ -112,6 +120,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsBetween{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsBetween<T>(T value, T minimum, T maximum, string name)
{
@ -121,6 +130,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsNotBetween{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsNotBetween<T>(T value, T minimum, T maximum, string name)
{
@ -130,6 +140,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsBetweenOrEqualTo{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo<T>(T value, T minimum, T maximum, string name)
{
@ -139,6 +150,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsNotBetweenOrEqualTo{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of values being tested.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo<T>(T value, T minimum, T maximum, string name)
{

Просмотреть файл

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@ -14,7 +13,6 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Helper methods to throw exceptions
/// </summary>
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")]
internal static partial class ThrowHelper
{
/// <summary>

Просмотреть файл

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@ -15,7 +14,6 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Helper methods to throw exceptions
/// </summary>
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")]
internal static partial class ThrowHelper
{
/// <summary>

Просмотреть файл

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
#nullable enable
@ -13,7 +12,6 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Helper methods to throw exceptions
/// </summary>
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")]
internal static partial class ThrowHelper
{
/// <summary>
@ -89,7 +87,7 @@ namespace Microsoft.Toolkit.Diagnostics
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo"/> fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo(string,int,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int size, string name)
@ -107,19 +105,19 @@ namespace Microsoft.Toolkit.Diagnostics
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeOver"/> fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThan"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeOver(string text, int size, string name)
public 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()}");
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeAtLeast"/> fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeGreaterThanOrEqualTo"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeAtLeast(string text, int size, string name)
public 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()}");
}
@ -134,12 +132,48 @@ namespace Microsoft.Toolkit.Diagnostics
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo"/> fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo(string,int,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public 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()}");
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeEqualTo(string,string,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public 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()}");
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.HasSizeLessThanOrEqualTo(string,string,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public 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()}");
}
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsInRangeFor(int,string,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public 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()}");
}
/// <summary>
/// Throws an <see cref="ArgumentOutOfRangeException"/> when <see cref="Guard.IsNotInRangeFor(int,string,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public 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()}");
}
}
}

Просмотреть файл

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.Toolkit.Extensions;
@ -15,7 +14,6 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Helper methods to throw exceptions
/// </summary>
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")]
internal static partial class ThrowHelper
{
/// <summary>

Просмотреть файл

@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@ -14,13 +13,12 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Helper methods to throw exceptions
/// </summary>
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")]
internal static partial class ThrowHelper
{
#pragma warning disable CS0419
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNull{T}"/> fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNull{T}(T,string)"/> (where <typeparamref name="T"/> is <see langword="class"/>) fails.
/// </summary>
/// <typeparam name="T">The type of the input value.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsNull<T>(T value, string name)
where T : class
@ -29,8 +27,9 @@ namespace Microsoft.Toolkit.Diagnostics
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNull{T}"/> fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNull{T}(T,string)"/> (where <typeparamref name="T"/> is <see langword="struct"/>) fails.
/// </summary>
/// <typeparam name="T">The type of the input value.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsNull<T>(T? value, string name)
where T : struct
@ -39,18 +38,19 @@ namespace Microsoft.Toolkit.Diagnostics
}
/// <summary>
/// Throws an <see cref="ArgumentNullException"/> when <see cref="Guard.IsNotNull{T}"/> fails.
/// Throws an <see cref="ArgumentNullException"/> when <see cref="Guard.IsNotNull{T}(T,string)"/> fails.
/// </summary>
/// <typeparam name="T">The type of the input value.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentNullExceptionForIsNotNull<T>(string name)
{
ThrowArgumentNullException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be not null)");
}
#pragma warning restore CS0419
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsOfType{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of the input value.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsOfType<T>(object value, string name)
{
@ -60,6 +60,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotOfType{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of the input value.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsNotOfType<T>(object value, string name)
{
@ -87,6 +88,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsAssignableToType{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type being checked against.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsAssignableToType<T>(object value, string name)
{
@ -96,6 +98,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsNotAssignableToType{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type being checked against.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsNotAssignableToType<T>(object value, string name)
{
@ -123,6 +126,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsBitwiseEqualTo{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of input values being compared.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForsBitwiseEqualTo<T>(T value, T target, string name)
where T : unmanaged
@ -133,6 +137,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsReferenceEqualTo{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of input value being compared.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsReferenceEqualTo<T>(string name)
where T : class
@ -143,6 +148,7 @@ namespace Microsoft.Toolkit.Diagnostics
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsReferenceNotEqualTo{T}"/> fails.
/// </summary>
/// <typeparam name="T">The type of input value being compared.</typeparam>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsReferenceNotEqualTo<T>(string name)
where T : class
@ -151,7 +157,7 @@ namespace Microsoft.Toolkit.Diagnostics
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsTrue"/> fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsTrue(bool,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsTrue(string name)
@ -160,12 +166,30 @@ namespace Microsoft.Toolkit.Diagnostics
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsFalse"/> fails.
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsTrue(bool,string,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsTrue(string name, string message)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be true, was false: {message.ToAssertString()}");
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsFalse(bool,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsFalse(string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true");
}
/// <summary>
/// Throws an <see cref="ArgumentException"/> when <see cref="Guard.IsFalse(bool,string,string)"/> fails.
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsFalse(string name, string message)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} must be false, was true: {message.ToAssertString()}");
}
}
}

Просмотреть файл

@ -107,10 +107,10 @@ namespace Microsoft.Toolkit.Extensions
return type.ToString();
}
/* Atomically get or build the display string for the current type.
* Manually create a static lambda here to enable caching of the generated closure.
* This is a workaround for the missing caching for method group conversions, and should
* be removed once this issue is resolved: https://github.com/dotnet/roslyn/issues/5835. */
// Atomically get or build the display string for the current type.
// Manually create a static lambda here to enable caching of the generated closure.
// This is a workaround for the missing caching for method group conversions, and should
// be removed once this issue is resolved: https://github.com/dotnet/roslyn/issues/5835.
return DisplayNames.GetValue(type, t => FormatDisplayString(t));
}
}

Просмотреть файл

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>8.0</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Title>Windows Community Toolkit .NET Standard</Title>
@ -16,8 +16,14 @@
<DebugType>Full</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Memory" Version="4.5.3" />
<!-- .NET Standard 2.0 doesn't have the Span<T> type -->
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Memory" Version="4.5.4" />
</ItemGroup>
<!-- .NET Standard 2.1 doesn't have the Unsafe type -->
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1' ">
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.7.1" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Microsoft.Toolkit\Microsoft.Toolkit.csproj" />
</ItemGroup>
<Import Project="..\UnitTests.Shared\UnitTests.Shared.projitems" Label="Shared" />
</Project>

Просмотреть файл

Просмотреть файл

@ -2,11 +2,11 @@
// 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.Collections.Specialized;
using System.Linq;
using FluentAssertions;
using Microsoft.Toolkit.Collections;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Specialized;
namespace UnitTests.Collections
{

Просмотреть файл

@ -2,11 +2,11 @@
// 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 FluentAssertions;
using Microsoft.Toolkit.Collections;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;
namespace UnitTests.Collections
{

Просмотреть файл

@ -2,11 +2,11 @@
// 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.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Microsoft.Toolkit.Collections;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Linq;
namespace UnitTests.Collections
{

Просмотреть файл

@ -2,9 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using FluentAssertions;
using Microsoft.Toolkit.Collections;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections;
using System.Collections.Generic;
@ -12,6 +9,9 @@ using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using FluentAssertions;
using Microsoft.Toolkit.Collections;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTests.Collections
{

Просмотреть файл

@ -72,41 +72,41 @@ namespace UnitTests.Diagnostics
[TestCategory("Guard")]
[TestMethod]
public void Test_Guard_HasSizeOver_ArrayOk()
public void Test_Guard_HasSizeGreaterThan_ArrayOk()
{
Guard.HasSizeOver(new int[5], 2, nameof(Test_Guard_HasSizeOver_ArrayOk));
Guard.HasSizeGreaterThan(new int[5], 2, nameof(Test_Guard_HasSizeGreaterThan_ArrayOk));
}
[TestCategory("Guard")]
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void Test_Guard_HasSizeOver_ArrayEqualFail()
public void Test_Guard_HasSizeGreaterThan_ArrayEqualFail()
{
Guard.HasSizeOver(new int[4], 4, nameof(Test_Guard_HasSizeOver_ArrayEqualFail));
Guard.HasSizeGreaterThan(new int[4], 4, nameof(Test_Guard_HasSizeGreaterThan_ArrayEqualFail));
}
[TestCategory("Guard")]
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void Test_Guard_HasSizeOver_ArraSmallerFail()
public void Test_Guard_HasSizeGreaterThan_ArraSmallerFail()
{
Guard.HasSizeOver(new int[1], 4, nameof(Test_Guard_HasSizeOver_ArraSmallerFail));
Guard.HasSizeGreaterThan(new int[1], 4, nameof(Test_Guard_HasSizeGreaterThan_ArraSmallerFail));
}
[TestCategory("Guard")]
[TestMethod]
public void Test_Guard_HasSizeAtLeast_ArrayOk()
public void Test_Guard_HasSizeGreaterThanOrEqualTo_ArrayOk()
{
Guard.HasSizeAtLeast(new int[5], 2, nameof(Test_Guard_HasSizeAtLeast_ArrayOk));
Guard.HasSizeAtLeast(new int[2], 2, nameof(Test_Guard_HasSizeAtLeast_ArrayOk));
Guard.HasSizeGreaterThanOrEqualTo(new int[5], 2, nameof(Test_Guard_HasSizeGreaterThanOrEqualTo_ArrayOk));
Guard.HasSizeGreaterThanOrEqualTo(new int[2], 2, nameof(Test_Guard_HasSizeGreaterThanOrEqualTo_ArrayOk));
}
[TestCategory("Guard")]
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void Test_Guard_HasSizeAtLeast_ArrayFail()
public void Test_Guard_HasSizeGreaterThanOrEqualTo_ArrayFail()
{
Guard.HasSizeOver(new int[1], 4, nameof(Test_Guard_HasSizeAtLeast_ArrayFail));
Guard.HasSizeGreaterThan(new int[1], 4, nameof(Test_Guard_HasSizeGreaterThanOrEqualTo_ArrayFail));
}
[TestCategory("Guard")]

Просмотреть файл

@ -216,6 +216,7 @@ namespace UnitTests.Diagnostics
public void Test_Guard_IsTrue_Ok()
{
Guard.IsTrue(true, nameof(Test_Guard_IsTrue_Ok));
Guard.IsTrue(true, nameof(Test_Guard_IsTrue_Ok), "Hello world");
}
[TestCategory("Guard")]
@ -226,11 +227,32 @@ namespace UnitTests.Diagnostics
Guard.IsTrue(false, nameof(Test_Guard_IsTrue_Fail));
}
[TestCategory("Guard")]
[TestMethod]
public void Test_Guard_IsTrue_Fail_WithMessage()
{
try
{
Guard.IsTrue(false, nameof(Test_Guard_IsTrue_Fail_WithMessage), "Hello world");
}
catch (ArgumentException e)
{
Assert.IsTrue(e.Message.Contains("\"Hello world\""));
return;
}
// Compiler detects this is unreachable from attribute,
// but we leave the assertion to double check that's valid
Assert.Fail();
}
[TestCategory("Guard")]
[TestMethod]
public void Test_Guard_IsFalse_Ok()
{
Guard.IsFalse(false, nameof(Test_Guard_IsFalse_Ok));
Guard.IsFalse(false, nameof(Test_Guard_IsFalse_Ok), "Hello world");
}
[TestCategory("Guard")]
@ -241,6 +263,24 @@ namespace UnitTests.Diagnostics
Guard.IsFalse(true, nameof(Test_Guard_IsFalse_Fail));
}
[TestCategory("Guard")]
[TestMethod]
public void Test_Guard_IsFalse_Fail_WithMessage()
{
try
{
Guard.IsFalse(true, nameof(Test_Guard_IsFalse_Fail_WithMessage), "Hello world");
}
catch (ArgumentException e)
{
Assert.IsTrue(e.Message.Contains("\"Hello world\""));
return;
}
Assert.Fail();
}
[TestCategory("Guard")]
[TestMethod]
public void Test_Guard_IsLessThan_Ok()
@ -315,7 +355,7 @@ namespace UnitTests.Diagnostics
[TestMethod]
public void Test_Guard_IsGreaterThanOrEqualTo_Ok()
{
Guard.IsGreaterThanOrEqualTo(2,1, nameof(Test_Guard_IsGreaterThanOrEqualTo_Ok));
Guard.IsGreaterThanOrEqualTo(2, 1, nameof(Test_Guard_IsGreaterThanOrEqualTo_Ok));
Guard.IsGreaterThanOrEqualTo(1, 1, nameof(Test_Guard_IsGreaterThanOrEqualTo_Ok));
Guard.IsGreaterThanOrEqualTo(MathF.PI, 1, nameof(Test_Guard_IsGreaterThanOrEqualTo_Ok));
Guard.IsGreaterThanOrEqualTo(MathF.PI, MathF.PI, nameof(Test_Guard_IsGreaterThanOrEqualTo_Ok));

Просмотреть файл

@ -2,11 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.Toolkit.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Diagnostics;
using System.Linq;
using Microsoft.Toolkit.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTests.Extensions
{
@ -174,9 +174,9 @@ namespace UnitTests.Extensions
{
int[][] array =
{
new int[] { 5, 2, 4 },
new int[] { 6, 3 },
new int[] { 7 }
new int[] { 5, 2, 4 },
new int[] { 6, 3 },
new int[] { 7 }
};
var col = array.GetColumn(1).ToArray();
@ -188,7 +188,7 @@ namespace UnitTests.Extensions
[TestMethod]
public void Test_ArrayExtensions_Jagged_GetColumn_Exception()
{
int[][] array =
int[][] array =
{
new int[] { 5, 2, 4 },
new int[] { 6, 3 },

Просмотреть файл

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>4e9466d1-d5aa-46ac-801b-c8fdab79f0d4</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>UnitTests.Shared</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Collections\IntGroup.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Collections\ObservableGroupedCollectionExtensionsTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Collections\ObservableGroupedCollectionTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Collections\ObservableGroupTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Collections\ReadOnlyObservableGroupedCollectionTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Collections\ReadOnlyObservableGroupTests.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\Test_Guard.Array.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\Test_Guard.Comparable.Numeric.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Diagnostics\Test_Guard.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\Test_ArrayExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\Test_TypeExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\Test_ValueTypeExtensions.cs" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>4e9466d1-d5aa-46ac-801b-c8fdab79f0d4</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="UnitTests.Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>

Просмотреть файл

@ -0,0 +1,7 @@
[*.{cs,vb}]
# SA1601: Partial elements should be documented
dotnet_diagnostic.SA1601.severity = none
dotnet_diagnostic.CS1573.severity = none
dotnet_diagnostic.CS1591.severity = none
dotnet_diagnostic.CS1712.severity = none

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 276 B

После

Ширина:  |  Высота:  |  Размер: 276 B

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 2.6 KiB

После

Ширина:  |  Высота:  |  Размер: 2.6 KiB

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 1.3 KiB

После

Ширина:  |  Высота:  |  Размер: 1.3 KiB

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 417 B

После

Ширина:  |  Высота:  |  Размер: 417 B

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 204 B

После

Ширина:  |  Высота:  |  Размер: 204 B

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 291 B

После

Ширина:  |  Высота:  |  Размер: 291 B

Просмотреть файл

До

Ширина:  |  Высота:  |  Размер: 1.2 KiB

После

Ширина:  |  Высота:  |  Размер: 1.2 KiB

Просмотреть файл

@ -5,11 +5,7 @@
using Microsoft.Toolkit.Uwp.UI.Controls;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnitTests.UI.Controls
{

Просмотреть файл

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше