Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Adding ValidateTypeIsBlittable SpanHelper method and rename constant #24626

Merged
merged 5 commits into from
Oct 18, 2017
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
5 changes: 2 additions & 3 deletions src/System.Memory/src/System.Memory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<CLSCompliant>false</CLSCompliant>
<DocumentationFile>$(OutputPath)$(MSBuildProjectName).xml</DocumentationFile>
<IsPartialFacadeAssembly Condition="'$(TargetGroup)' == 'netcoreapp' OR '$(TargetGroup)' == 'uap'">true</IsPartialFacadeAssembly>
<DefineConstants Condition="'$(IsPartialFacadeAssembly)' == 'true'">$(DefineConstants);IsPartialFacade</DefineConstants>
<DefineConstants Condition="'$(IsPartialFacadeAssembly)' != 'true'">$(DefineConstants);netstandard</DefineConstants>
<DefineConstants Condition="'$(TargetGroup)'=='netcoreapp'">$(DefineConstants);netcoreapp</DefineConstants>
<DefineConstants Condition="'$(TargetGroup)'=='netstandard1.1'">$(DefineConstants);netstandard11</DefineConstants>
</PropertyGroup>
Expand Down Expand Up @@ -55,9 +55,8 @@
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.Extensions" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Runtime.CompilerServices.Unsafe" />
<Reference Condition="'$(TargetGroup)' != 'netstandard1.1'" Include="System.Numerics.Vectors" />
<Reference Condition="'$(TargetGroup)' != 'netstandard1.1'" Include="System.Runtime.CompilerServices.Unsafe" />
<ProjectReference Condition="'$(TargetGroup)' == 'netstandard1.1'" Include="..\..\System.Runtime.CompilerServices.Unsafe\src\System.Runtime.CompilerServices.Unsafe.ilproj" />
</ItemGroup>
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' == 'true'">
<Compile Include="System\SpanExtensions.Fast.cs" />
Expand Down
20 changes: 10 additions & 10 deletions src/System.Memory/src/System/Buffers/Binary/Reader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ public static ulong ReverseEndianness(ulong value)
public static T ReadMachineEndian<T>(ReadOnlySpan<byte> buffer)
where T : struct
{
#if IsPartialFacade
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
#if netstandard
if (SpanHelpers.IsReferenceOrContainsReferences<T>())
{
throw new ArgumentException(SR.Format(SR.Argument_InvalidTypeWithPointersNotSupported, typeof(T)));
ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(T));
}
#else
if (SpanHelpers.IsReferenceOrContainsReferences<T>())
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
{
ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(T));
throw new ArgumentException(SR.Format(SR.Argument_InvalidTypeWithPointersNotSupported, typeof(T)));
}
#endif
if (Unsafe.SizeOf<T>() > buffer.Length)
Expand All @@ -124,15 +124,15 @@ public static T ReadMachineEndian<T>(ReadOnlySpan<byte> buffer)
public static bool TryReadMachineEndian<T>(ReadOnlySpan<byte> buffer, out T value)
where T : struct
{
#if IsPartialFacade
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
#if netstandard
if (SpanHelpers.IsReferenceOrContainsReferences<T>())
{
throw new ArgumentException(SR.Format(SR.Argument_InvalidTypeWithPointersNotSupported, typeof(T)));
ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(T));
}
#else
if (SpanHelpers.IsReferenceOrContainsReferences<T>())
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
{
ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(T));
throw new ArgumentException(SR.Format(SR.Argument_InvalidTypeWithPointersNotSupported, typeof(T)));
}
#endif
if (Unsafe.SizeOf<T>() > (uint)buffer.Length)
Expand Down
20 changes: 10 additions & 10 deletions src/System.Memory/src/System/Buffers/Binary/Writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public static partial class BinaryPrimitives
public static void WriteMachineEndian<T>(Span<byte> buffer, ref T value)
where T : struct
{
#if IsPartialFacade
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
#if netstandard
if (SpanHelpers.IsReferenceOrContainsReferences<T>())
{
throw new ArgumentException(SR.Format(SR.Argument_InvalidTypeWithPointersNotSupported, typeof(T)));
ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(T));
}
#else
if (SpanHelpers.IsReferenceOrContainsReferences<T>())
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
{
ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(T));
throw new ArgumentException(SR.Format(SR.Argument_InvalidTypeWithPointersNotSupported, typeof(T)));
}
#endif
if ((uint)Unsafe.SizeOf<T>() > (uint)buffer.Length)
Expand All @@ -42,15 +42,15 @@ public static void WriteMachineEndian<T>(Span<byte> buffer, ref T value)
public static bool TryWriteMachineEndian<T>(Span<byte> buffer, ref T value)
where T : struct
{
#if IsPartialFacade
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
#if netstandard
if (SpanHelpers.IsReferenceOrContainsReferences<T>())
{
throw new ArgumentException(SR.Format(SR.Argument_InvalidTypeWithPointersNotSupported, typeof(T)));
ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(T));
}
#else
if (SpanHelpers.IsReferenceOrContainsReferences<T>())
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
{
ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(T));
throw new ArgumentException(SR.Format(SR.Argument_InvalidTypeWithPointersNotSupported, typeof(T)));
}
#endif
if (Unsafe.SizeOf<T>() > (uint)buffer.Length)
Expand Down