Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 0f7b728

Browse files
akoeplingerstephentoub
authored andcommitted
Add CLSCompliant(false) to APIs in System.Memory (#25471)
* Add ClsCompliant(false) to Span.cs/ReadOnlySpan.cs It's there in the coreclr version but not in the corefx version: - https://github.com/dotnet/coreclr/blob/3c0149df881a3846af3405013db530551308cfbe/src/mscorlib/shared/System/ReadOnlySpan.cs#L85 - https://github.com/dotnet/coreclr/blob/3c0149df881a3846af3405013db530551308cfbe/src/mscorlib/shared/System/Span.cs#L97 * Reenable assembly CLSCompliant for System.Memory
1 parent fb94fc7 commit 0f7b728

File tree

14 files changed

+80
-2
lines changed

14 files changed

+80
-2
lines changed

src/System.Memory/ref/System.Memory.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public readonly ref struct ReadOnlySpan<T>
1212
public static ReadOnlySpan<T> Empty { get { throw null; } }
1313
public ReadOnlySpan(T[] array) { throw null; }
1414
public ReadOnlySpan(T[] array, int start, int length) { throw null; }
15+
[CLSCompliant(false)]
1516
public unsafe ReadOnlySpan(void* pointer, int length) { throw null; }
1617
public bool IsEmpty { get { throw null; } }
1718
public T this[int index] { get { throw null; }}
@@ -50,6 +51,7 @@ public readonly ref struct Span<T>
5051
public static Span<T> Empty { get { throw null; } }
5152
public Span(T[] array) { throw null; }
5253
public Span(T[] array, int start, int length) { throw null; }
54+
[CLSCompliant(false)]
5355
public unsafe Span(void* pointer, int length) { throw null; }
5456
public bool IsEmpty { get { throw null; } }
5557
public ref T this[int index] { get { throw null; } }
@@ -187,7 +189,9 @@ namespace System.Buffers
187189
{
188190
public unsafe struct MemoryHandle : IDisposable
189191
{
192+
[CLSCompliant(false)]
190193
public MemoryHandle(IRetainable owner, void* pointer = null, System.Runtime.InteropServices.GCHandle handle = default(System.Runtime.InteropServices.GCHandle)) { throw null; }
194+
[CLSCompliant(false)]
191195
public void* Pointer { get { throw null; } }
192196
public bool HasPointer { get { throw null; } }
193197
public void Dispose() { throw null; }
@@ -227,13 +231,17 @@ namespace System.Buffers.Binary
227231
{
228232
public static class BinaryPrimitives
229233
{
234+
[CLSCompliant(false)]
230235
public static sbyte ReverseEndianness(sbyte value) { throw null; }
231236
public static byte ReverseEndianness(byte value) { throw null; }
232237
public static short ReverseEndianness(short value) { throw null; }
238+
[CLSCompliant(false)]
233239
public static ushort ReverseEndianness(ushort value) { throw null; }
234240
public static int ReverseEndianness(int value) { throw null; }
241+
[CLSCompliant(false)]
235242
public static uint ReverseEndianness(uint value) { throw null; }
236243
public static long ReverseEndianness(long value) { throw null; }
244+
[CLSCompliant(false)]
237245
public static ulong ReverseEndianness(ulong value) { throw null; }
238246

239247
public static T ReadMachineEndian<T>(ReadOnlySpan<byte> buffer) where T : struct { throw null; }
@@ -242,29 +250,41 @@ public static class BinaryPrimitives
242250
public static short ReadInt16LittleEndian(ReadOnlySpan<byte> buffer) { throw null; }
243251
public static int ReadInt32LittleEndian(ReadOnlySpan<byte> buffer) { throw null; }
244252
public static long ReadInt64LittleEndian(ReadOnlySpan<byte> buffer) { throw null; }
253+
[CLSCompliant(false)]
245254
public static ushort ReadUInt16LittleEndian(ReadOnlySpan<byte> buffer) { throw null; }
255+
[CLSCompliant(false)]
246256
public static uint ReadUInt32LittleEndian(ReadOnlySpan<byte> buffer) { throw null; }
257+
[CLSCompliant(false)]
247258
public static ulong ReadUInt64LittleEndian(ReadOnlySpan<byte> buffer) { throw null; }
248259

249260
public static bool TryReadInt16LittleEndian(ReadOnlySpan<byte> buffer, out short value) { throw null; }
250261
public static bool TryReadInt32LittleEndian(ReadOnlySpan<byte> buffer, out int value) { throw null; }
251262
public static bool TryReadInt64LittleEndian(ReadOnlySpan<byte> buffer, out long value) { throw null; }
263+
[CLSCompliant(false)]
252264
public static bool TryReadUInt16LittleEndian(ReadOnlySpan<byte> buffer, out ushort value) { throw null; }
265+
[CLSCompliant(false)]
253266
public static bool TryReadUInt32LittleEndian(ReadOnlySpan<byte> buffer, out uint value) { throw null; }
267+
[CLSCompliant(false)]
254268
public static bool TryReadUInt64LittleEndian(ReadOnlySpan<byte> buffer, out ulong value) { throw null; }
255269

256270
public static short ReadInt16BigEndian(ReadOnlySpan<byte> buffer) { throw null; }
257271
public static int ReadInt32BigEndian(ReadOnlySpan<byte> buffer) { throw null; }
258272
public static long ReadInt64BigEndian(ReadOnlySpan<byte> buffer) { throw null; }
273+
[CLSCompliant(false)]
259274
public static ushort ReadUInt16BigEndian(ReadOnlySpan<byte> buffer) { throw null; }
275+
[CLSCompliant(false)]
260276
public static uint ReadUInt32BigEndian(ReadOnlySpan<byte> buffer) { throw null; }
277+
[CLSCompliant(false)]
261278
public static ulong ReadUInt64BigEndian(ReadOnlySpan<byte> buffer) { throw null; }
262279

263280
public static bool TryReadInt16BigEndian(ReadOnlySpan<byte> buffer, out short value) { throw null; }
264281
public static bool TryReadInt32BigEndian(ReadOnlySpan<byte> buffer, out int value) { throw null; }
265282
public static bool TryReadInt64BigEndian(ReadOnlySpan<byte> buffer, out long value) { throw null; }
283+
[CLSCompliant(false)]
266284
public static bool TryReadUInt16BigEndian(ReadOnlySpan<byte> buffer, out ushort value) { throw null; }
285+
[CLSCompliant(false)]
267286
public static bool TryReadUInt32BigEndian(ReadOnlySpan<byte> buffer, out uint value) { throw null; }
287+
[CLSCompliant(false)]
268288
public static bool TryReadUInt64BigEndian(ReadOnlySpan<byte> buffer, out ulong value) { throw null; }
269289

270290
public static void WriteMachineEndian<T>(Span<byte> buffer, ref T value) where T : struct { throw null; }
@@ -273,29 +293,41 @@ public static class BinaryPrimitives
273293
public static void WriteInt16LittleEndian(Span<byte> buffer, short value) { throw null; }
274294
public static void WriteInt32LittleEndian(Span<byte> buffer, int value) { throw null; }
275295
public static void WriteInt64LittleEndian(Span<byte> buffer, long value) { throw null; }
296+
[CLSCompliant(false)]
276297
public static void WriteUInt16LittleEndian(Span<byte> buffer, ushort value) { throw null; }
298+
[CLSCompliant(false)]
277299
public static void WriteUInt32LittleEndian(Span<byte> buffer, uint value) { throw null; }
300+
[CLSCompliant(false)]
278301
public static void WriteUInt64LittleEndian(Span<byte> buffer, ulong value) { throw null; }
279302

280303
public static bool TryWriteInt16LittleEndian(Span<byte> buffer, short value) { throw null; }
281304
public static bool TryWriteInt32LittleEndian(Span<byte> buffer, int value) { throw null; }
282305
public static bool TryWriteInt64LittleEndian(Span<byte> buffer, long value) { throw null; }
306+
[CLSCompliant(false)]
283307
public static bool TryWriteUInt16LittleEndian(Span<byte> buffer, ushort value) { throw null; }
308+
[CLSCompliant(false)]
284309
public static bool TryWriteUInt32LittleEndian(Span<byte> buffer, uint value) { throw null; }
310+
[CLSCompliant(false)]
285311
public static bool TryWriteUInt64LittleEndian(Span<byte> buffer, ulong value) { throw null; }
286312

287313
public static void WriteInt16BigEndian(Span<byte> buffer, short value) { throw null; }
288314
public static void WriteInt32BigEndian(Span<byte> buffer, int value) { throw null; }
289315
public static void WriteInt64BigEndian(Span<byte> buffer, long value) { throw null; }
316+
[CLSCompliant(false)]
290317
public static void WriteUInt16BigEndian(Span<byte> buffer, ushort value) { throw null; }
318+
[CLSCompliant(false)]
291319
public static void WriteUInt32BigEndian(Span<byte> buffer, uint value) { throw null; }
320+
[CLSCompliant(false)]
292321
public static void WriteUInt64BigEndian(Span<byte> buffer, ulong value) { throw null; }
293322

294323
public static bool TryWriteInt16BigEndian(Span<byte> buffer, short value) { throw null; }
295324
public static bool TryWriteInt32BigEndian(Span<byte> buffer, int value) { throw null; }
296325
public static bool TryWriteInt64BigEndian(Span<byte> buffer, long value) { throw null; }
326+
[CLSCompliant(false)]
297327
public static bool TryWriteUInt16BigEndian(Span<byte> buffer, ushort value) { throw null; }
328+
[CLSCompliant(false)]
298329
public static bool TryWriteUInt32BigEndian(Span<byte> buffer, uint value) { throw null; }
330+
[CLSCompliant(false)]
299331
public static bool TryWriteUInt64BigEndian(Span<byte> buffer, ulong value) { throw null; }
300332
}
301333
}
@@ -346,11 +378,15 @@ public static class Utf8Formatter
346378
public static bool TryFormat(short value, Span<byte> buffer, out int bytesWritten, StandardFormat format = default) => throw null;
347379
public static bool TryFormat(int value, Span<byte> buffer, out int bytesWritten, StandardFormat format = default) => throw null;
348380
public static bool TryFormat(long value, Span<byte> buffer, out int bytesWritten, StandardFormat format = default) => throw null;
381+
[CLSCompliant(false)]
349382
public static bool TryFormat(sbyte value, Span<byte> buffer, out int bytesWritten, StandardFormat format = default) => throw null;
350383
public static bool TryFormat(float value, Span<byte> buffer, out int bytesWritten, StandardFormat format = default) => throw null;
351384
public static bool TryFormat(TimeSpan value, Span<byte> buffer, out int bytesWritten, StandardFormat format = default) => throw null;
385+
[CLSCompliant(false)]
352386
public static bool TryFormat(ushort value, Span<byte> buffer, out int bytesWritten, StandardFormat format = default) => throw null;
387+
[CLSCompliant(false)]
353388
public static bool TryFormat(uint value, Span<byte> buffer, out int bytesWritten, StandardFormat format = default) => throw null;
389+
[CLSCompliant(false)]
354390
public static bool TryFormat(ulong value, Span<byte> buffer, out int bytesWritten, StandardFormat format = default) => throw null;
355391
}
356392
public static class Utf8Parser
@@ -365,11 +401,15 @@ public static class Utf8Parser
365401
public static bool TryParse(ReadOnlySpan<byte> text, out short value, out int bytesConsumed, char standardFormat = default) => throw null;
366402
public static bool TryParse(ReadOnlySpan<byte> text, out int value, out int bytesConsumed, char standardFormat = default) => throw null;
367403
public static bool TryParse(ReadOnlySpan<byte> text, out long value, out int bytesConsumed, char standardFormat = default) => throw null;
404+
[CLSCompliant(false)]
368405
public static bool TryParse(ReadOnlySpan<byte> text, out sbyte value, out int bytesConsumed, char standardFormat = default) => throw null;
369406
public static bool TryParse(ReadOnlySpan<byte> text, out float value, out int bytesConsumed, char standardFormat = default) => throw null;
370407
public static bool TryParse(ReadOnlySpan<byte> text, out TimeSpan value, out int bytesConsumed, char standardFormat = default) => throw null;
408+
[CLSCompliant(false)]
371409
public static bool TryParse(ReadOnlySpan<byte> text, out ushort value, out int bytesConsumed, char standardFormat = default) => throw null;
410+
[CLSCompliant(false)]
372411
public static bool TryParse(ReadOnlySpan<byte> text, out uint value, out int bytesConsumed, char standardFormat = default) => throw null;
412+
[CLSCompliant(false)]
373413
public static bool TryParse(ReadOnlySpan<byte> text, out ulong value, out int bytesConsumed, char standardFormat = default) => throw null;
374414
}
375415
}

src/System.Memory/ref/System.Memory.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
44
<PropertyGroup>
55
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
6-
<CLSCompliant>false</CLSCompliant>
76
<ProjectGuid>{E883935B-D8FD-4FC9-A189-9D9E7F7EF550}</ProjectGuid>
87
<IsPartialFacadeAssembly Condition="'$(TargetGroup)' == 'netcoreapp' Or '$(TargetGroup)' == 'uap'">true</IsPartialFacadeAssembly>
98
</PropertyGroup>

src/System.Memory/src/System.Memory.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<PropertyGroup>
55
<ProjectGuid>{4BBC8F69-D03E-4432-AA8A-D458FA5B235A}</ProjectGuid>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7-
<CLSCompliant>false</CLSCompliant>
87
<DocumentationFile>$(OutputPath)$(MSBuildProjectName).xml</DocumentationFile>
98
<IsPartialFacadeAssembly Condition="'$(TargetGroup)' == 'netcoreapp' OR '$(TargetGroup)' == 'uap'">true</IsPartialFacadeAssembly>
109
<DefineConstants Condition="'$(IsPartialFacadeAssembly)' != 'true'">$(DefineConstants);netstandard</DefineConstants>

src/System.Memory/src/System/Buffers/Binary/Reader.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static partial class BinaryPrimitives
2121
/// This allows the caller to read a struct of numeric primitives and reverse each field
2222
/// rather than having to skip sbyte fields.
2323
/// </summary>
24+
[CLSCompliant(false)]
2425
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2526
public static sbyte ReverseEndianness(sbyte value)
2627
{
@@ -62,6 +63,7 @@ public static byte ReverseEndianness(byte value)
6263
/// <summary>
6364
/// Reverses a primitive value - performs an endianness swap
6465
/// </summary>
66+
[CLSCompliant(false)]
6567
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6668
public static ushort ReverseEndianness(ushort value)
6769
{
@@ -71,6 +73,7 @@ public static ushort ReverseEndianness(ushort value)
7173
/// <summary>
7274
/// Reverses a primitive value - performs an endianness swap
7375
/// </summary>
76+
[CLSCompliant(false)]
7477
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7578
public static uint ReverseEndianness(uint value)
7679
{
@@ -82,6 +85,7 @@ public static uint ReverseEndianness(uint value)
8285
/// <summary>
8386
/// Reverses a primitive value - performs an endianness swap
8487
/// </summary>
88+
[CLSCompliant(false)]
8589
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8690
public static ulong ReverseEndianness(ulong value)
8791
{

src/System.Memory/src/System/Buffers/Binary/ReaderBigEndian.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public static long ReadInt64BigEndian(ReadOnlySpan<byte> buffer)
5353
/// <summary>
5454
/// Reads a UInt16 out of a read-only span of bytes as big endian.
5555
/// </summary>
56+
[CLSCompliant(false)]
5657
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5758
public static ushort ReadUInt16BigEndian(ReadOnlySpan<byte> buffer)
5859
{
@@ -67,6 +68,7 @@ public static ushort ReadUInt16BigEndian(ReadOnlySpan<byte> buffer)
6768
/// <summary>
6869
/// Reads a UInt32 out of a read-only span of bytes as big endian.
6970
/// </summary>
71+
[CLSCompliant(false)]
7072
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7173
public static uint ReadUInt32BigEndian(ReadOnlySpan<byte> buffer)
7274
{
@@ -81,6 +83,7 @@ public static uint ReadUInt32BigEndian(ReadOnlySpan<byte> buffer)
8183
/// <summary>
8284
/// Reads a UInt64 out of a read-only span of bytes as big endian.
8385
/// </summary>
86+
[CLSCompliant(false)]
8487
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8588
public static ulong ReadUInt64BigEndian(ReadOnlySpan<byte> buffer)
8689
{
@@ -141,6 +144,7 @@ public static bool TryReadInt64BigEndian(ReadOnlySpan<byte> buffer, out long val
141144
/// Reads a UInt16 out of a read-only span of bytes as big endian.
142145
/// <returns>If the span is too small to contain a UInt16, return false.</returns>
143146
/// </summary>
147+
[CLSCompliant(false)]
144148
[MethodImpl(MethodImplOptions.AggressiveInlining)]
145149
public static bool TryReadUInt16BigEndian(ReadOnlySpan<byte> buffer, out ushort value)
146150
{
@@ -156,6 +160,7 @@ public static bool TryReadUInt16BigEndian(ReadOnlySpan<byte> buffer, out ushort
156160
/// Reads a UInt32 out of a read-only span of bytes as big endian.
157161
/// <returns>If the span is too small to contain a UInt32, return false.</returns>
158162
/// </summary>
163+
[CLSCompliant(false)]
159164
[MethodImpl(MethodImplOptions.AggressiveInlining)]
160165
public static bool TryReadUInt32BigEndian(ReadOnlySpan<byte> buffer, out uint value)
161166
{
@@ -171,6 +176,7 @@ public static bool TryReadUInt32BigEndian(ReadOnlySpan<byte> buffer, out uint va
171176
/// Reads a UInt64 out of a read-only span of bytes as big endian.
172177
/// <returns>If the span is too small to contain a UInt64, return false.</returns>
173178
/// </summary>
179+
[CLSCompliant(false)]
174180
[MethodImpl(MethodImplOptions.AggressiveInlining)]
175181
public static bool TryReadUInt64BigEndian(ReadOnlySpan<byte> buffer, out ulong value)
176182
{

src/System.Memory/src/System/Buffers/Binary/ReaderLittleEndian.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public static long ReadInt64LittleEndian(ReadOnlySpan<byte> buffer)
5353
/// <summary>
5454
/// Reads a UInt16 out of a read-only span of bytes as little endian.
5555
/// </summary>
56+
[CLSCompliant(false)]
5657
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5758
public static ushort ReadUInt16LittleEndian(ReadOnlySpan<byte> buffer)
5859
{
@@ -67,6 +68,7 @@ public static ushort ReadUInt16LittleEndian(ReadOnlySpan<byte> buffer)
6768
/// <summary>
6869
/// Reads a UInt32 out of a read-only span of bytes as little endian.
6970
/// </summary>
71+
[CLSCompliant(false)]
7072
[MethodImpl(MethodImplOptions.AggressiveInlining)]
7173
public static uint ReadUInt32LittleEndian(ReadOnlySpan<byte> buffer)
7274
{
@@ -81,6 +83,7 @@ public static uint ReadUInt32LittleEndian(ReadOnlySpan<byte> buffer)
8183
/// <summary>
8284
/// Reads a UInt64 out of a read-only span of bytes as little endian.
8385
/// </summary>
86+
[CLSCompliant(false)]
8487
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8588
public static ulong ReadUInt64LittleEndian(ReadOnlySpan<byte> buffer)
8689
{
@@ -141,6 +144,7 @@ public static bool TryReadInt64LittleEndian(ReadOnlySpan<byte> buffer, out long
141144
/// Reads a UInt16 out of a read-only span of bytes as little endian.
142145
/// <returns>If the span is too small to contain a UInt16, return false.</returns>
143146
/// </summary>
147+
[CLSCompliant(false)]
144148
[MethodImpl(MethodImplOptions.AggressiveInlining)]
145149
public static bool TryReadUInt16LittleEndian(ReadOnlySpan<byte> buffer, out ushort value)
146150
{
@@ -156,6 +160,7 @@ public static bool TryReadUInt16LittleEndian(ReadOnlySpan<byte> buffer, out usho
156160
/// Reads a UInt32 out of a read-only span of bytes as little endian.
157161
/// <returns>If the span is too small to contain a UInt32, return false.</returns>
158162
/// </summary>
163+
[CLSCompliant(false)]
159164
[MethodImpl(MethodImplOptions.AggressiveInlining)]
160165
public static bool TryReadUInt32LittleEndian(ReadOnlySpan<byte> buffer, out uint value)
161166
{
@@ -171,6 +176,7 @@ public static bool TryReadUInt32LittleEndian(ReadOnlySpan<byte> buffer, out uint
171176
/// Reads a UInt64 out of a read-only span of bytes as little endian.
172177
/// <returns>If the span is too small to contain a UInt64, return false.</returns>
173178
/// </summary>
179+
[CLSCompliant(false)]
174180
[MethodImpl(MethodImplOptions.AggressiveInlining)]
175181
public static bool TryReadUInt64LittleEndian(ReadOnlySpan<byte> buffer, out ulong value)
176182
{

0 commit comments

Comments
 (0)