Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libraries/System.Memory/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@
<data name="NotSupported_CannotCallGetHashCodeOnSpan" xml:space="preserve">
<value>GetHashCode() on Span and ReadOnlySpan is not supported.</value>
</data>
<data name="Argument_InvalidTypeWithPointersNotSupported" xml:space="preserve">
<value>Cannot use type '{0}'. Only value types without pointers or references are supported.</value>
<data name="Argument_TypeContainsReferences" xml:space="preserve">
<value>The type '{0}' is not supported because it contains references.</value>
</data>
<data name="Argument_DestinationTooShort" xml:space="preserve">
<value>Destination is too short.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@
<data name="Argument_InvalidEnumValue" xml:space="preserve">
<value>The value '{0}' is not valid for this usage of the type {1}.</value>
</data>
<data name="Argument_InvalidTypeWithPointersNotSupported" xml:space="preserve">
<value>Cannot use type '{0}'. Only value types without pointers or references are supported.</value>
<data name="Argument_TypeContainsReferences" xml:space="preserve">
<value>The type '{0}' is not supported because it contains references.</value>
</data>
<data name="DestinationTooShort" xml:space="preserve">
<value>Destination is too short.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ internal static void ThrowArgumentOutOfRangeException()
}

[DoesNotReturn]
internal static void ThrowInvalidTypeWithPointersNotSupported(Type targetType)
internal static void ThrowArgument_TypeContainsReferences(Type targetType)
{
throw new ArgumentException(SR.Format(SR.Argument_InvalidTypeWithPointersNotSupported, targetType));
throw new ArgumentException(SR.Format(SR.Argument_TypeContainsReferences, targetType));
}

[DoesNotReturn]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1375,8 +1375,8 @@
<data name="Argument_InvalidTypeName" xml:space="preserve">
<value>The name of the type is invalid.</value>
</data>
<data name="Argument_InvalidTypeWithPointersNotSupported" xml:space="preserve">
<value>Cannot use type '{0}'. Only value types without pointers or references are supported.</value>
<data name="Argument_TypeContainsReferences" xml:space="preserve">
<value>The type '{0}' is not supported because it contains references.</value>
</data>
<data name="Argument_InvalidUnity" xml:space="preserve">
<value>Type '{0}' is not deserializable.</value>
Expand Down Expand Up @@ -1456,9 +1456,6 @@
<data name="Argument_NeedNonGenericType" xml:space="preserve">
<value>The specified Type must not be a generic type.</value>
</data>
<data name="Argument_NeedStructWithNoRefs" xml:space="preserve">
<value>The specified Type must be a struct containing no references.</value>
</data>
<data name="Argument_NegativeFieldOffsetNotPermitted" xml:space="preserve">
<value>Negative field offset is not allowed.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public ReadOnlySpan(T[]? array, int start, int length)
public unsafe ReadOnlySpan(void* pointer, int length)
{
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
if (length < 0)
ThrowHelper.ThrowArgumentOutOfRangeException();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static unsafe Span<byte> AsBytes<T>(Span<T> span)
where T : struct
{
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));

return new Span<byte>(
ref Unsafe.As<T, byte>(ref GetReference(span)),
Expand All @@ -54,7 +54,7 @@ public static unsafe ReadOnlySpan<byte> AsBytes<T>(ReadOnlySpan<T> span)
where T : struct
{
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));

return new ReadOnlySpan<byte>(
ref Unsafe.As<T, byte>(ref GetReference(span)),
Expand Down Expand Up @@ -116,9 +116,9 @@ public static unsafe Span<TTo> Cast<TFrom, TTo>(Span<TFrom> span)
where TTo : struct
{
if (RuntimeHelpers.IsReferenceOrContainsReferences<TFrom>())
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TFrom));
ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(TFrom));
if (RuntimeHelpers.IsReferenceOrContainsReferences<TTo>())
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TTo));
ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(TTo));

// Use unsigned integers - unsigned division by constant (especially by power of 2)
// and checked casts are faster and smaller.
Expand Down Expand Up @@ -171,9 +171,9 @@ public static unsafe ReadOnlySpan<TTo> Cast<TFrom, TTo>(ReadOnlySpan<TFrom> span
where TTo : struct
{
if (RuntimeHelpers.IsReferenceOrContainsReferences<TFrom>())
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TFrom));
ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(TFrom));
if (RuntimeHelpers.IsReferenceOrContainsReferences<TTo>())
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(TTo));
ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(TTo));

// Use unsigned integers - unsigned division by constant (especially by power of 2)
// and checked casts are faster and smaller.
Expand Down Expand Up @@ -470,7 +470,7 @@ public static unsafe T Read<T>(ReadOnlySpan<byte> source)
{
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
{
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
}
if (sizeof(T) > source.Length)
{
Expand All @@ -489,7 +489,7 @@ public static unsafe bool TryRead<T>(ReadOnlySpan<byte> source, out T value)
{
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
{
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
}
if (sizeof(T) > (uint)source.Length)
{
Expand All @@ -509,7 +509,7 @@ public static unsafe void Write<T>(Span<byte> destination, in T value)
{
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
{
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
}
if ((uint)sizeof(T) > (uint)destination.Length)
{
Expand All @@ -528,7 +528,7 @@ public static unsafe bool TryWrite<T>(Span<byte> destination, in T value)
{
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
{
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
}
if (sizeof(T) > (uint)destination.Length)
{
Expand All @@ -551,7 +551,7 @@ public static unsafe ref T AsRef<T>(Span<byte> span)
{
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
{
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
}
if (sizeof(T) > (uint)span.Length)
{
Expand All @@ -573,7 +573,7 @@ public static unsafe ref readonly T AsRef<T>(ReadOnlySpan<byte> span)
{
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
{
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
}
if (sizeof(T) > (uint)span.Length)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ internal static uint AlignedSizeOf<T>() where T : struct
internal static uint SizeOf<T>() where T : struct
{
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
throw new ArgumentException(SR.Argument_NeedStructWithNoRefs);
ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));

return (uint)sizeof(T);
}
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Private.CoreLib/src/System/Span.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public Span(T[]? array, int start, int length)
public unsafe Span(void* pointer, int length)
{
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
ThrowHelper.ThrowInvalidTypeWithPointersNotSupported(typeof(T));
ThrowHelper.ThrowArgument_TypeContainsReferences(typeof(T));
if (length < 0)
ThrowHelper.ThrowArgumentOutOfRangeException();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ internal static void ThrowArrayTypeMismatchException()
}

[DoesNotReturn]
internal static void ThrowInvalidTypeWithPointersNotSupported(Type targetType)
internal static void ThrowArgument_TypeContainsReferences(Type targetType)
{
throw new ArgumentException(SR.Format(SR.Argument_InvalidTypeWithPointersNotSupported, targetType));
throw new ArgumentException(SR.Format(SR.Argument_TypeContainsReferences, targetType));
}

[DoesNotReturn]
Expand Down