diff --git a/Microsoft.Toolkit.Parsers/Markdown/Blocks/ListBlock.cs b/Microsoft.Toolkit.Parsers/Markdown/Blocks/ListBlock.cs
index ba44b0e6664..f1e90403d3a 100644
--- a/Microsoft.Toolkit.Parsers/Markdown/Blocks/ListBlock.cs
+++ b/Microsoft.Toolkit.Parsers/Markdown/Blocks/ListBlock.cs
@@ -11,7 +11,7 @@
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
{
diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/Properties/AssemblyInfo.cs b/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/Properties/AssemblyInfo.cs
index 64a4e43ebc0..22ad66eb095 100644
--- a/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/Properties/AssemblyInfo.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/Properties/AssemblyInfo.cs
@@ -8,5 +8,5 @@
// 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")]
\ No newline at end of file
diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/Properties/AssemblyInfo.cs b/Microsoft.Toolkit.Uwp.UI.Controls/Properties/AssemblyInfo.cs
index 64a4e43ebc0..22ad66eb095 100644
--- a/Microsoft.Toolkit.Uwp.UI.Controls/Properties/AssemblyInfo.cs
+++ b/Microsoft.Toolkit.Uwp.UI.Controls/Properties/AssemblyInfo.cs
@@ -8,5 +8,5 @@
// 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")]
\ No newline at end of file
diff --git a/Microsoft.Toolkit/Diagnostics/Attributes/DoesNotReturnIfAttribute.cs b/Microsoft.Toolkit/Diagnostics/Attributes/DoesNotReturnIfAttribute.cs
new file mode 100644
index 00000000000..bde310c41bd
--- /dev/null
+++ b/Microsoft.Toolkit/Diagnostics/Attributes/DoesNotReturnIfAttribute.cs
@@ -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
+{
+ ///
+ /// Specifies that a given also indicates
+ /// whether the method will not return (eg. throw an exception).
+ ///
+ /// Internal copy of the .NET Standard 2.1 attribute.
+ [AttributeUsage(AttributeTargets.Parameter)]
+ internal sealed class DoesNotReturnIfAttribute : Attribute
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The condition parameter value. Code after the method will be considered unreachable
+ /// by diagnostics if the argument to the associated parameter matches this value.
+ ///
+ public DoesNotReturnIfAttribute(bool parameterValue)
+ {
+ ParameterValue = parameterValue;
+ }
+
+ ///
+ /// Gets a value indicating whether the parameter value should be .
+ ///
+ public bool ParameterValue { get; }
+ }
+}
+
+#endif
\ No newline at end of file
diff --git a/Microsoft.Toolkit/Diagnostics/Attributes/NotNullAttribute.cs b/Microsoft.Toolkit/Diagnostics/Attributes/NotNullAttribute.cs
new file mode 100644
index 00000000000..80a3342c478
--- /dev/null
+++ b/Microsoft.Toolkit/Diagnostics/Attributes/NotNullAttribute.cs
@@ -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
+{
+ ///
+ /// Specifies that an output will not be even if the corresponding type allows it.
+ /// Specifies that an input argument was not when the call returns.
+ ///
+ /// Internal copy of the .NET Standard 2.1 attribute.
+ [AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property | AttributeTargets.ReturnValue)]
+ internal sealed class NotNullAttribute : Attribute
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public NotNullAttribute()
+ {
+ }
+ }
+}
+
+#endif
\ No newline at end of file
diff --git a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.g.cs b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.g.cs
index 346241db8cc..6ccd58b3c5f 100644
--- a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.g.cs
+++ b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.g.cs
@@ -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 @@ public static void HasSizeNotEqualTo(Span span, int size, string name)
/// The name of the input parameter being tested.
/// Thrown if the size of is <= .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void HasSizeOver(Span span, int size, string name)
+ public static void HasSizeGreaterThan(Span span, int size, string name)
{
if (span.Length <= size)
{
- ThrowHelper.ThrowArgumentExceptionForHasSizeOver(span, size, name);
+ ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(span, size, name);
}
}
@@ -111,11 +110,11 @@ public static void HasSizeOver(Span span, int size, string name)
/// The name of the input parameter being tested.
/// Thrown if the size of is < .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void HasSizeAtLeast(Span span, int size, string name)
+ public static void HasSizeGreaterThanOrEqualTo(Span span, int size, string name)
{
if (span.Length < size)
{
- ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(span, size, name);
+ ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(span, size, name);
}
}
@@ -296,11 +295,11 @@ public static void HasSizeNotEqualTo(ReadOnlySpan span, int size, string n
/// The name of the input parameter being tested.
/// Thrown if the size of is <= .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void HasSizeOver(ReadOnlySpan span, int size, string name)
+ public static void HasSizeGreaterThan(ReadOnlySpan span, int size, string name)
{
if (span.Length <= size)
{
- ThrowHelper.ThrowArgumentExceptionForHasSizeOver(span, size, name);
+ ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(span, size, name);
}
}
@@ -313,11 +312,11 @@ public static void HasSizeOver(ReadOnlySpan span, int size, string name)
/// The name of the input parameter being tested.
/// Thrown if the size of is < .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void HasSizeAtLeast(ReadOnlySpan span, int size, string name)
+ public static void HasSizeGreaterThanOrEqualTo(ReadOnlySpan span, int size, string name)
{
if (span.Length < size)
{
- ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(span, size, name);
+ ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(span, size, name);
}
}
@@ -498,11 +497,11 @@ public static void HasSizeNotEqualTo(Memory memory, int size, string name)
/// The name of the input parameter being tested.
/// Thrown if the size of is <= .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void HasSizeOver(Memory memory, int size, string name)
+ public static void HasSizeGreaterThan(Memory memory, int size, string name)
{
if (memory.Length <= size)
{
- ThrowHelper.ThrowArgumentExceptionForHasSizeOver(memory, size, name);
+ ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(memory, size, name);
}
}
@@ -515,11 +514,11 @@ public static void HasSizeOver(Memory memory, int size, string name)
/// The name of the input parameter being tested.
/// Thrown if the size of is < .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void HasSizeAtLeast(Memory memory, int size, string name)
+ public static void HasSizeGreaterThanOrEqualTo(Memory memory, int size, string name)
{
if (memory.Length < size)
{
- ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(memory, size, name);
+ ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(memory, size, name);
}
}
@@ -700,11 +699,11 @@ public static void HasSizeNotEqualTo(ReadOnlyMemory memory, int size, stri
/// The name of the input parameter being tested.
/// Thrown if the size of is <= .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void HasSizeOver(ReadOnlyMemory memory, int size, string name)
+ public static void HasSizeGreaterThan(ReadOnlyMemory memory, int size, string name)
{
if (memory.Length <= size)
{
- ThrowHelper.ThrowArgumentExceptionForHasSizeOver(memory, size, name);
+ ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(memory, size, name);
}
}
@@ -717,11 +716,11 @@ public static void HasSizeOver(ReadOnlyMemory memory, int size, string nam
/// The name of the input parameter being tested.
/// Thrown if the size of is < .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void HasSizeAtLeast(ReadOnlyMemory memory, int size, string name)
+ public static void HasSizeGreaterThanOrEqualTo(ReadOnlyMemory memory, int size, string name)
{
if (memory.Length < size)
{
- ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(memory, size, name);
+ ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(memory, size, name);
}
}
@@ -902,11 +901,11 @@ public static void HasSizeNotEqualTo(T[] array, int size, string name)
/// The name of the input parameter being tested.
/// Thrown if the size of is <= .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void HasSizeOver(T[] array, int size, string name)
+ public static void HasSizeGreaterThan(T[] array, int size, string name)
{
if (array.Length <= size)
{
- ThrowHelper.ThrowArgumentExceptionForHasSizeOver(array, size, name);
+ ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(array, size, name);
}
}
@@ -919,11 +918,11 @@ public static void HasSizeOver(T[] array, int size, string name)
/// The name of the input parameter being tested.
/// Thrown if the size of is < .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void HasSizeAtLeast(T[] array, int size, string name)
+ public static void HasSizeGreaterThanOrEqualTo(T[] array, int size, string name)
{
if (array.Length < size)
{
- ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(array, size, name);
+ ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(array, size, name);
}
}
@@ -1104,11 +1103,11 @@ public static void HasSizeNotEqualTo(List list, int size, string name)
/// The name of the input parameter being tested.
/// Thrown if the size of is <= .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void HasSizeOver(List list, int size, string name)
+ public static void HasSizeGreaterThan(List list, int size, string name)
{
if (list.Count <= size)
{
- ThrowHelper.ThrowArgumentExceptionForHasSizeOver((ICollection)list, size, name);
+ ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan((ICollection)list, size, name);
}
}
@@ -1121,11 +1120,11 @@ public static void HasSizeOver(List list, int size, string name)
/// The name of the input parameter being tested.
/// Thrown if the size of is < .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void HasSizeAtLeast(List list, int size, string name)
+ public static void HasSizeGreaterThanOrEqualTo(List list, int size, string name)
{
if (list.Count < size)
{
- ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast((ICollection)list, size, name);
+ ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo((ICollection)list, size, name);
}
}
@@ -1306,11 +1305,11 @@ public static void HasSizeNotEqualTo(ICollection collection, int size, str
/// The name of the input parameter being tested.
/// Thrown if the size of is <= .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void HasSizeOver(ICollection collection, int size, string name)
+ public static void HasSizeGreaterThan(ICollection collection, int size, string name)
{
if (collection.Count <= size)
{
- ThrowHelper.ThrowArgumentExceptionForHasSizeOver(collection, size, name);
+ ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(collection, size, name);
}
}
@@ -1323,11 +1322,11 @@ public static void HasSizeOver(ICollection collection, int size, string na
/// The name of the input parameter being tested.
/// Thrown if the size of is < .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void HasSizeAtLeast(ICollection collection, int size, string name)
+ public static void HasSizeGreaterThanOrEqualTo(ICollection collection, int size, string name)
{
if (collection.Count < size)
{
- ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(collection, size, name);
+ ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(collection, size, name);
}
}
@@ -1508,11 +1507,11 @@ public static void HasSizeNotEqualTo(IReadOnlyCollection collection, int s
/// The name of the input parameter being tested.
/// Thrown if the size of is <= .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void HasSizeOver(IReadOnlyCollection collection, int size, string name)
+ public static void HasSizeGreaterThan(IReadOnlyCollection collection, int size, string name)
{
if (collection.Count <= size)
{
- ThrowHelper.ThrowArgumentExceptionForHasSizeOver(collection, size, name);
+ ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThan(collection, size, name);
}
}
@@ -1525,11 +1524,11 @@ public static void HasSizeOver(IReadOnlyCollection collection, int size, s
/// The name of the input parameter being tested.
/// Thrown if the size of is < .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void HasSizeAtLeast(IReadOnlyCollection collection, int size, string name)
+ public static void HasSizeGreaterThanOrEqualTo(IReadOnlyCollection collection, int size, string name)
{
if (collection.Count < size)
{
- ThrowHelper.ThrowArgumentExceptionForHasSizeAtLeast(collection, size, name);
+ ThrowHelper.ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(collection, size, name);
}
}
diff --git a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.tt b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.tt
index 37430fced50..20e46530a30 100644
--- a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.tt
+++ b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Collection.tt
@@ -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 =>
/// The name of the input parameter being tested.
/// Thrown if the size of is <= .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void HasSizeOver(<#=item.Type#> <#=item.Name#>, int size, string name)
+ public static void HasSizeGreaterThan(<#=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 =>
/// The name of the input parameter being tested.
/// Thrown if the size of is < .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void HasSizeAtLeast(<#=item.Type#> <#=item.Name#>, int size, string name)
+ public static void HasSizeGreaterThanOrEqualTo(<#=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(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#>)
{
diff --git a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.g.cs b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.g.cs
index ec0d08fd788..5da28215540 100644
--- a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.g.cs
+++ b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.g.cs
@@ -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;
diff --git a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.tt b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.tt
index 3cb7ee32093..aeb86f9c700 100644
--- a/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.tt
+++ b/Microsoft.Toolkit/Diagnostics/Generated/Guard.Comparable.Numeric.tt
@@ -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;
diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs
index e40c0d94fe5..f6ee371e87f 100644
--- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs
+++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.g.cs
@@ -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
///
/// Helper methods to throw exceptions
///
- [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")]
internal static partial class ThrowHelper
{
///
@@ -50,19 +47,19 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(Span span, i
}
///
- /// Throws an when (or an overload) fails.
+ /// Throws an when (or an overload) fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowArgumentExceptionForHasSizeOver(Span span, int size, string name)
+ public static void ThrowArgumentExceptionForHasSizeGreaterThan(Span span, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}");
}
///
- /// Throws an when (or an overload) fails.
+ /// Throws an when (or an overload) fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowArgumentExceptionForHasSizeAtLeast(Span span, int size, string name)
+ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Span span, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Span).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}");
}
@@ -149,19 +146,19 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlySpan
}
///
- /// Throws an when (or an overload) fails.
+ /// Throws an when (or an overload) fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowArgumentExceptionForHasSizeOver(ReadOnlySpan span, int size, string name)
+ public static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlySpan span, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size over {size}, had a size of {span.Length.ToAssertString()}");
}
///
- /// Throws an when (or an overload) fails.
+ /// Throws an when (or an overload) fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowArgumentExceptionForHasSizeAtLeast(ReadOnlySpan span, int size, string name)
+ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlySpan span, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlySpan).ToTypeString()}) must have a size of at least {size}, had a size of {span.Length.ToAssertString()}");
}
@@ -248,19 +245,19 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(Memory memor
}
///
- /// Throws an when (or an overload) fails.
+ /// Throws an when (or an overload) fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowArgumentExceptionForHasSizeOver(Memory memory, int size, string name)
+ public static void ThrowArgumentExceptionForHasSizeGreaterThan(Memory memory, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}");
}
///
- /// Throws an when (or an overload) fails.
+ /// Throws an when (or an overload) fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowArgumentExceptionForHasSizeAtLeast(Memory memory, int size, string name)
+ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(Memory memory, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(Memory).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}");
}
@@ -347,19 +344,19 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ReadOnlyMemory<
}
///
- /// Throws an when (or an overload) fails.
+ /// Throws an when (or an overload) fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowArgumentExceptionForHasSizeOver(ReadOnlyMemory memory, int size, string name)
+ public static void ThrowArgumentExceptionForHasSizeGreaterThan(ReadOnlyMemory memory, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size over {size}, had a size of {memory.Length.ToAssertString()}");
}
///
- /// Throws an when (or an overload) fails.
+ /// Throws an when (or an overload) fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowArgumentExceptionForHasSizeAtLeast(ReadOnlyMemory memory, int size, string name)
+ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ReadOnlyMemory memory, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ReadOnlyMemory).ToTypeString()}) must have a size of at least {size}, had a size of {memory.Length.ToAssertString()}");
}
@@ -446,19 +443,19 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(T[] array, int
}
///
- /// Throws an when (or an overload) fails.
+ /// Throws an when (or an overload) fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowArgumentExceptionForHasSizeOver(T[] array, int size, string name)
+ public static void ThrowArgumentExceptionForHasSizeGreaterThan(T[] array, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size over {size}, had a size of {array.Length.ToAssertString()}");
}
///
- /// Throws an when (or an overload) fails.
+ /// Throws an when (or an overload) fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowArgumentExceptionForHasSizeAtLeast(T[] array, int size, string name)
+ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(T[] array, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(T[]).ToTypeString()}) must have a size of at least {size}, had a size of {array.Length.ToAssertString()}");
}
@@ -545,19 +542,19 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(List list, i
}
///
- /// Throws an when (or an overload) fails.
+ /// Throws an when (or an overload) fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowArgumentExceptionForHasSizeOver(List list, int size, string name)
+ public static void ThrowArgumentExceptionForHasSizeGreaterThan(List list, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size over {size}, had a size of {list.Count.ToAssertString()}");
}
///
- /// Throws an when (or an overload) fails.
+ /// Throws an when (or an overload) fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowArgumentExceptionForHasSizeAtLeast(List list, int size, string name)
+ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(List list, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(List).ToTypeString()}) must have a size of at least {size}, had a size of {list.Count.ToAssertString()}");
}
@@ -644,19 +641,19 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(ICollection
}
///
- /// Throws an when (or an overload) fails.
+ /// Throws an when (or an overload) fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowArgumentExceptionForHasSizeOver(ICollection collection, int size, string name)
+ public static void ThrowArgumentExceptionForHasSizeGreaterThan(ICollection collection, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}");
}
///
- /// Throws an when (or an overload) fails.
+ /// Throws an when (or an overload) fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowArgumentExceptionForHasSizeAtLeast(ICollection collection, int size, string name)
+ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(ICollection collection, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(ICollection).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}");
}
@@ -743,19 +740,19 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(IReadOnlyCollec
}
///
- /// Throws an when (or an overload) fails.
+ /// Throws an when (or an overload) fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowArgumentExceptionForHasSizeOver(IReadOnlyCollection collection, int size, string name)
+ public static void ThrowArgumentExceptionForHasSizeGreaterThan(IReadOnlyCollection collection, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size over {size}, had a size of {collection.Count.ToAssertString()}");
}
///
- /// Throws an when (or an overload) fails.
+ /// Throws an when (or an overload) fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowArgumentExceptionForHasSizeAtLeast(IReadOnlyCollection collection, int size, string name)
+ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(IReadOnlyCollection collection, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(IReadOnlyCollection).ToTypeString()}) must have a size of at least {size}, had a size of {collection.Count.ToAssertString()}");
}
diff --git a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt
index 4aaac7f607a..c27e68efbca 100644
--- a/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt
+++ b/Microsoft.Toolkit/Diagnostics/Generated/ThrowHelper.Collection.tt
@@ -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
///
/// Helper methods to throw exceptions
///
- [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")]
internal static partial class ThrowHelper
{
<#
@@ -54,19 +48,19 @@ GenerateTextForItems(EnumerableTypes, item =>
}
///
- /// Throws an when (or an overload) fails.
+ /// Throws an when (or an overload) fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowArgumentExceptionForHasSizeOver(<#=item.Type#> <#=item.Name#>, int size, string name)
+ public static void ThrowArgumentExceptionForHasSizeGreaterThan(<#=item.Type#> <#=item.Name#>, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size over {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}");
}
///
- /// Throws an when (or an overload) fails.
+ /// Throws an when (or an overload) fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
- public static void ThrowArgumentExceptionForHasSizeAtLeast(<#=item.Type#> <#=item.Name#>, int size, string name)
+ public static void ThrowArgumentExceptionForHasSizeGreaterThanOrEqualTo(<#=item.Type#> <#=item.Name#>, int size, string name)
{
ThrowArgumentException(name, $"Parameter {name.ToAssertString()} ({typeof(<#=item.Type#>).ToTypeString()}) must have a size of at least {size}, had a size of {<#=item.Name#>.<#=item.Size#>.ToAssertString()}");
}
diff --git a/Microsoft.Toolkit/Diagnostics/Generated/TypeInfo.ttinclude b/Microsoft.Toolkit/Diagnostics/Generated/TypeInfo.ttinclude
index 04e29500538..1bcffa5513f 100644
--- a/Microsoft.Toolkit/Diagnostics/Generated/TypeInfo.ttinclude
+++ b/Microsoft.Toolkit/Diagnostics/Generated/TypeInfo.ttinclude
@@ -2,6 +2,9 @@
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".g.cs"#>
+// =====================
+// Auto generated file
+// =====================
<#+
///
/// A model representing the info on an enumerable type
diff --git a/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Generic.cs b/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Generic.cs
index 1c974232ecd..f07d3297a2b 100644
--- a/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Generic.cs
+++ b/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Generic.cs
@@ -98,11 +98,11 @@ public static void IsNotEqualTo(T value, T target, string name)
public static void IsBitwiseEqualTo(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))
diff --git a/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Numeric.cs b/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Numeric.cs
index 712b5fa6784..0e23e7fbaf6 100644
--- a/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Numeric.cs
+++ b/Microsoft.Toolkit/Diagnostics/Guard.Comparable.Numeric.cs
@@ -25,17 +25,17 @@ public static partial class Guard
[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 @@ public static void IsNotCloseTo(int value, int target, uint delta, string name)
[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);
diff --git a/Microsoft.Toolkit/Diagnostics/Guard.String.cs b/Microsoft.Toolkit/Diagnostics/Guard.String.cs
index 05286bee164..bf4f56beb3b 100644
--- a/Microsoft.Toolkit/Diagnostics/Guard.String.cs
+++ b/Microsoft.Toolkit/Diagnostics/Guard.String.cs
@@ -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 @@ public static void IsNullOrEmpty(string? text, string name)
/// The name of the input parameter being tested.
/// Thrown if is or empty.
[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 @@ public static void IsNullOrWhitespace(string? text, string name)
/// The name of the input parameter being tested.
/// Thrown if is or whitespace.
[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 @@ public static void HasSizeNotEqualTo(string text, int size, string name)
/// The name of the input parameter being tested.
/// Thrown if the size of is <= .
[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 @@ public static void HasSizeOver(string text, int size, string name)
/// The name of the input parameter being tested.
/// Thrown if the size of is < .
[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 @@ public static void HasSizeLessThanOrEqualTo(string text, int size, string name)
ThrowHelper.ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(text, size, name);
}
}
+
+ ///
+ /// Asserts that the source instance must have the same size of a destination instance.
+ ///
+ /// The source instance to check the size for.
+ /// The destination instance to check the size for.
+ /// The name of the input parameter being tested.
+ /// Thrown if the size of is != the one of .
+ /// The type is immutable, but the name of this API is kept for consistency with the other overloads.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void HasSizeEqualTo(string source, string destination, string name)
+ {
+ if (source.Length != destination.Length)
+ {
+ ThrowHelper.ThrowArgumentExceptionForHasSizeEqualTo(source, destination, name);
+ }
+ }
+
+ ///
+ /// Asserts that the source instance must have a size of less than or equal to that of a destination instance.
+ ///
+ /// The source instance to check the size for.
+ /// The destination instance to check the size for.
+ /// The name of the input parameter being tested.
+ /// Thrown if the size of is > the one of .
+ /// The type is immutable, but the name of this API is kept for consistency with the other overloads.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void HasSizeLessThanOrEqualTo(string source, string destination, string name)
+ {
+ if (source.Length > destination.Length)
+ {
+ ThrowHelper.ThrowArgumentExceptionForHasSizeLessThanOrEqualTo(source, destination, name);
+ }
+ }
+
+ ///
+ /// Asserts that the input index is valid for a given instance.
+ ///
+ /// The input index to be used to access .
+ /// The input instance to use to validate .
+ /// The name of the input parameter being tested.
+ /// Thrown if is not valid to access .
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void IsInRangeFor(int index, string text, string name)
+ {
+ if ((uint)index >= (uint)text.Length)
+ {
+ ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsInRangeFor(index, text, name);
+ }
+ }
+
+ ///
+ /// Asserts that the input index is not valid for a given instance.
+ ///
+ /// The input index to be used to access .
+ /// The input instance to use to validate .
+ /// The name of the input parameter being tested.
+ /// Thrown if is valid to access .
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void IsNotInRangeFor(int index, string text, string name)
+ {
+ if ((uint)index < (uint)text.Length)
+ {
+ ThrowHelper.ThrowArgumentOutOfRangeExceptionForIsNotInRangeFor(index, text, name);
+ }
+ }
}
}
diff --git a/Microsoft.Toolkit/Diagnostics/Guard.cs b/Microsoft.Toolkit/Diagnostics/Guard.cs
index a8703a4c04a..fb57977ba2d 100644
--- a/Microsoft.Toolkit/Diagnostics/Guard.cs
+++ b/Microsoft.Toolkit/Diagnostics/Guard.cs
@@ -25,7 +25,6 @@ public static partial class Guard
/// The name of the input parameter being tested.
/// Thrown if is not .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- [SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1119", Justification = "Negated pattern match expression")]
public static void IsNull(T? value, string name)
where T : class
{
@@ -44,7 +43,6 @@ public static void IsNull(T? value, string name)
/// Thrown if is not .
/// The method is generic to avoid boxing the parameters, if they are value types.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- [SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1119", Justification = "Negated pattern match expression")]
public static void IsNull(T? value, string name)
where T : struct
{
@@ -62,7 +60,7 @@ public static void IsNull(T? value, string name)
/// The name of the input parameter being tested.
/// Thrown if is .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void IsNotNull(T? value, string name)
+ public static void IsNotNull([NotNull] T? value, string name)
where T : class
{
if (value is null)
@@ -80,7 +78,7 @@ public static void IsNotNull(T? value, string name)
/// Thrown if is .
/// The method is generic to avoid boxing the parameters, if they are value types.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void IsNotNull(T? value, string name)
+ public static void IsNotNull([NotNull] T? value, string name)
where T : struct
{
if (value is null)
@@ -262,7 +260,7 @@ public static void IsReferenceNotEqualTo(T value, T target, string name)
/// The name of the input parameter being tested.
/// Thrown if is .
[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 @@ public static void IsTrue(bool value, string name)
}
}
+ ///
+ /// Asserts that the input value must be .
+ ///
+ /// The input to test.
+ /// The name of the input parameter being tested.
+ /// A message to display if is .
+ /// Thrown if is .
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void IsTrue([DoesNotReturnIf(false)] bool value, string name, string message)
+ {
+ if (!value)
+ {
+ ThrowHelper.ThrowArgumentExceptionForIsTrue(name, message);
+ }
+ }
+
///
/// Asserts that the input value must be .
///
@@ -277,12 +291,28 @@ public static void IsTrue(bool value, string name)
/// The name of the input parameter being tested.
/// Thrown if is .
[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);
}
}
+
+ ///
+ /// Asserts that the input value must be .
+ ///
+ /// The input to test.
+ /// The name of the input parameter being tested.
+ /// A message to display if is .
+ /// Thrown if is .
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void IsFalse([DoesNotReturnIf(true)] bool value, string name, string message)
+ {
+ if (value)
+ {
+ ThrowHelper.ThrowArgumentExceptionForIsFalse(name, message);
+ }
+ }
}
}
diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs
index 7f1a57d1b80..64a4ce44b48 100644
--- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs
+++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Collection.Generic.cs
@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
-using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@@ -14,12 +13,12 @@ namespace Microsoft.Toolkit.Diagnostics
///
/// Helper methods to throw exceptions
///
- [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")]
internal static partial class ThrowHelper
{
///
/// Throws an when fails.
///
+ /// The item of items in the input instance.
/// This method is needed because can't be used as a generic type parameter.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name)
@@ -30,7 +29,8 @@ public static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name)
///
/// Throws an when fails.
///
- /// This method is needed because can't be used as a generic type parameter.
+ /// The item of items in the input instance.
+ /// This method is needed because can't be used as a generic type parameter.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(string name)
{
@@ -40,6 +40,7 @@ public static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(string
///
/// Throws an when (or an overload) fails.
///
+ /// The item of items in the input collection.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsNotEmpty(string name)
{
diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs
index 0dab8651f21..ef901c3d136 100644
--- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs
+++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Generic.cs
@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
-using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@@ -14,12 +13,12 @@ namespace Microsoft.Toolkit.Diagnostics
///
/// Helper methods to throw exceptions
///
- [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")]
internal static partial class ThrowHelper
{
///
/// Throws an when fails.
///
+ /// The type of value type being tested.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsDefault(T value, string name)
where T : struct
@@ -30,6 +29,7 @@ public static void ThrowArgumentExceptionForIsDefault(T value, string name)
///
/// Throws an when fails.
///
+ /// The type of value type being tested.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsNotDefault(string name)
where T : struct
@@ -40,6 +40,7 @@ public static void ThrowArgumentExceptionForIsNotDefault(string name)
///
/// Throws an when fails.
///
+ /// The type of values being tested.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsEqualTo(T value, T target, string name)
{
@@ -49,6 +50,7 @@ public static void ThrowArgumentExceptionForIsEqualTo(T value, T target, stri
///
/// Throws an when fails.
///
+ /// The type of values being tested.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, string name)
{
@@ -58,6 +60,7 @@ public static void ThrowArgumentExceptionForIsNotEqualTo(T value, T target, s
///
/// Throws an when fails.
///
+ /// The type of values being tested.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T maximum, string name)
{
@@ -67,6 +70,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsLessThan(T value, T m
///
/// Throws an when fails.
///
+ /// The type of values being tested.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T value, T maximum, string name)
{
@@ -76,6 +80,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsLessThanOrEqualTo(T v
///
/// Throws an when fails.
///
+ /// The type of values being tested.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value, T minimum, string name)
{
@@ -85,6 +90,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThan(T value,
///
/// Throws an when fails.
///
+ /// The type of values being tested.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(T value, T minimum, string name)
{
@@ -94,6 +100,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsGreaterThanOrEqualTo(
///
/// Throws an when fails.
///
+ /// The type of values being tested.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T minimum, T maximum, string name)
{
@@ -103,6 +110,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsInRange(T value, T mi
///
/// Throws an when fails.
///
+ /// The type of values being tested.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, T minimum, T maximum, string name)
{
@@ -112,6 +120,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotInRange(T value, T
///
/// Throws an when fails.
///
+ /// The type of values being tested.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T minimum, T maximum, string name)
{
@@ -121,6 +130,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsBetween(T value, T mi
///
/// Throws an when fails.
///
+ /// The type of values being tested.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, T minimum, T maximum, string name)
{
@@ -130,6 +140,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsNotBetween(T value, T
///
/// Throws an when fails.
///
+ /// The type of values being tested.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T value, T minimum, T maximum, string name)
{
@@ -139,6 +150,7 @@ public static void ThrowArgumentOutOfRangeExceptionForIsBetweenOrEqualTo(T va
///
/// Throws an when fails.
///
+ /// The type of values being tested.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentOutOfRangeExceptionForIsNotBetweenOrEqualTo(T value, T minimum, T maximum, string name)
{
diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs
index ab05318ad6c..2db1ef888ab 100644
--- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs
+++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Comparable.Numeric.cs
@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
-using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@@ -14,7 +13,6 @@ namespace Microsoft.Toolkit.Diagnostics
///
/// Helper methods to throw exceptions
///
- [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")]
internal static partial class ThrowHelper
{
///
diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs
index 5dada175c32..218c1527480 100644
--- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs
+++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.IO.cs
@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
-using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@@ -15,7 +14,6 @@ namespace Microsoft.Toolkit.Diagnostics
///
/// Helper methods to throw exceptions
///
- [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")]
internal static partial class ThrowHelper
{
///
diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs
index 496507b6dc1..2835d1c4c0c 100644
--- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs
+++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.String.cs
@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
-using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
#nullable enable
@@ -13,7 +12,6 @@ namespace Microsoft.Toolkit.Diagnostics
///
/// Helper methods to throw exceptions
///
- [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")]
internal static partial class ThrowHelper
{
///
@@ -89,7 +87,7 @@ public static void ThrowArgumentExceptionForIsNotWhitespace(string text, string
}
///
- /// Throws an when fails.
+ /// Throws an when fails.
///
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForHasSizeEqualTo(string text, int size, string name)
@@ -107,19 +105,19 @@ public static void ThrowArgumentExceptionForHasSizeNotEqualTo(string text, int s
}
///
- /// Throws an when fails.
+ /// Throws an when fails.
///
[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()}");
}
///
- /// Throws an when fails.
+ /// Throws an when fails.
///
[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 @@ public static void ThrowArgumentExceptionForHasSizeLessThan(string text, int siz
}
///
- /// Throws an when fails.
+ /// Throws an when fails.
///
[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()}");
}
+
+ ///
+ /// Throws an when fails.
+ ///
+ [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()}");
+ }
+
+ ///
+ /// Throws an when fails.
+ ///
+ [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()}");
+ }
+
+ ///
+ /// Throws an when fails.
+ ///
+ [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()}");
+ }
+
+ ///
+ /// Throws an when fails.
+ ///
+ [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()}");
+ }
}
}
diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs
index 9fad34ea8d1..8b5a144d5e0 100644
--- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs
+++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.Tasks.cs
@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
-using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.Toolkit.Extensions;
@@ -15,7 +14,6 @@ namespace Microsoft.Toolkit.Diagnostics
///
/// Helper methods to throw exceptions
///
- [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")]
internal static partial class ThrowHelper
{
///
diff --git a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs
index 5436d9b48b4..bbc307deb9d 100644
--- a/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs
+++ b/Microsoft.Toolkit/Diagnostics/ThrowHelper.cs
@@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.
using System;
-using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.Toolkit.Extensions;
@@ -14,13 +13,12 @@ namespace Microsoft.Toolkit.Diagnostics
///
/// Helper methods to throw exceptions
///
- [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1618", Justification = "Internal helper methods")]
internal static partial class ThrowHelper
{
-#pragma warning disable CS0419
///
- /// Throws an when fails.
+ /// Throws an when (where is ) fails.
///
+ /// The type of the input value.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsNull(T value, string name)
where T : class
@@ -29,8 +27,9 @@ public static void ThrowArgumentExceptionForIsNull(T value, string name)
}
///
- /// Throws an when fails.
+ /// Throws an when (where is ) fails.
///
+ /// The type of the input value.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsNull(T? value, string name)
where T : struct
@@ -39,18 +38,19 @@ public static void ThrowArgumentExceptionForIsNull(T? value, string name)
}
///
- /// Throws an when fails.
+ /// Throws an when fails.
///
+ /// The type of the input value.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentNullExceptionForIsNotNull(string name)
{
ThrowArgumentNullException(name, $"Parameter {name.ToAssertString()} ({typeof(T).ToTypeString()}) must be not null)");
}
-#pragma warning restore CS0419
///
/// Throws an when fails.
///
+ /// The type of the input value.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsOfType(object value, string name)
{
@@ -60,6 +60,7 @@ public static void ThrowArgumentExceptionForIsOfType(object value, string nam
///
/// Throws an when fails.
///
+ /// The type of the input value.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsNotOfType(object value, string name)
{
@@ -87,6 +88,7 @@ public static void ThrowArgumentExceptionForIsNotOfType(object value, Type type,
///
/// Throws an when fails.
///
+ /// The type being checked against.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsAssignableToType(object value, string name)
{
@@ -96,6 +98,7 @@ public static void ThrowArgumentExceptionForIsAssignableToType(object value,
///
/// Throws an when fails.
///
+ /// The type being checked against.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForIsNotAssignableToType(object value, string name)
{
@@ -123,6 +126,7 @@ public static void ThrowArgumentExceptionForIsNotAssignableToType(object value,
///
/// Throws an when fails.
///
+ /// The type of input values being compared.
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentExceptionForsBitwiseEqualTo(T value, T target, string name)
where T : unmanaged
@@ -133,6 +137,7 @@ public static void ThrowArgumentExceptionForsBitwiseEqualTo(T value, T target
///
/// Throws an