Skip to content

Commit 112ce73

Browse files
Merge pull request #3901 from Sergio0694/bugfix/span2d-copyto-exception-info
Fixed exception message and docs for Span2D<T>.CopyTo(Span2D<T>)
2 parents 8463203 + f8c4009 commit 112ce73

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Microsoft.Toolkit.HighPerformance/Memory/Internals/ThrowHelper.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ public static void ThrowArgumentExceptionForDestinationTooShort()
2727
throw new ArgumentException("The target span is too short to copy all the current items to");
2828
}
2929

30+
/// <summary>
31+
/// Throws an <see cref="ArgumentException"/> when the target span does not have the same shape as the source.
32+
/// </summary>
33+
public static void ThrowArgumentExceptionForDestinationWithNotSameShape()
34+
{
35+
throw new ArgumentException("The target span does not have the same shape as the source one");
36+
}
37+
3038
/// <summary>
3139
/// Throws an <see cref="ArrayTypeMismatchException"/> when using an array of an invalid type.
3240
/// </summary>

Microsoft.Toolkit.HighPerformance/Memory/ReadOnlySpan2D{T}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,14 +654,14 @@ public void CopyTo(Span<T> destination)
654654
/// </summary>
655655
/// <param name="destination">The destination <see cref="Span2D{T}"/> instance.</param>
656656
/// <exception cref="ArgumentException">
657-
/// Thrown when <paramref name="destination" /> is shorter than the source <see cref="ReadOnlySpan2D{T}"/> instance.
657+
/// Thrown when <paramref name="destination" /> does not have the same shape as the source <see cref="ReadOnlySpan2D{T}"/> instance.
658658
/// </exception>
659659
public void CopyTo(Span2D<T> destination)
660660
{
661661
if (destination.Height != Height ||
662662
destination.Width != Width)
663663
{
664-
ThrowHelper.ThrowArgumentException();
664+
ThrowHelper.ThrowArgumentExceptionForDestinationWithNotSameShape();
665665
}
666666

667667
if (IsEmpty)

Microsoft.Toolkit.HighPerformance/Memory/Span2D{T}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,14 +767,14 @@ public void CopyTo(Span<T> destination)
767767
/// </summary>
768768
/// <param name="destination">The destination <see cref="Span2D{T}"/> instance.</param>
769769
/// <exception cref="ArgumentException">
770-
/// Thrown when <paramref name="destination" /> is shorter than the source <see cref="Span2D{T}"/> instance.
770+
/// Thrown when <paramref name="destination" /> does not have the same shape as the source <see cref="Span2D{T}"/> instance.
771771
/// </exception>
772772
public void CopyTo(Span2D<T> destination)
773773
{
774774
if (destination.Height != Height ||
775775
destination.width != this.width)
776776
{
777-
ThrowHelper.ThrowArgumentException();
777+
ThrowHelper.ThrowArgumentExceptionForDestinationWithNotSameShape();
778778
}
779779

780780
if (IsEmpty)

0 commit comments

Comments
 (0)