Skip to content

Resolve ILLink warnings in System.Memory.Data #54980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2021
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
7 changes: 5 additions & 2 deletions src/libraries/System.Memory.Data/ref/System.Memory.Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ namespace System
public partial class BinaryData
{
public BinaryData(byte[] data) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed.")]
public BinaryData(object? jsonSerializable, System.Text.Json.JsonSerializerOptions? options = null, System.Type? type = null) { }
public BinaryData(System.ReadOnlyMemory<byte> data) { }
public BinaryData(string data) { }
public static BinaryData Empty { get; }
public static System.BinaryData Empty { get { throw null; } }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
public static System.BinaryData FromBytes(byte[] data) { throw null; }
public static System.BinaryData FromBytes(System.ReadOnlyMemory<byte> data) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed.")]
public static System.BinaryData FromObjectAsJson<T>(T jsonSerializable, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
public static System.BinaryData FromStream(System.IO.Stream stream) { throw null; }
public static System.Threading.Tasks.Task<System.BinaryData> FromStreamAsync(System.IO.Stream stream, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand All @@ -27,6 +29,7 @@ public BinaryData(string data) { }
public static implicit operator System.ReadOnlySpan<byte> (System.BinaryData? data) { throw null; }
public byte[] ToArray() { throw null; }
public System.ReadOnlyMemory<byte> ToMemory() { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("JSON serialization and deserialization might require types that cannot be statically analyzed.")]
public T? ToObjectFromJson<T>(System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
public System.IO.Stream ToStream() { throw null; }
public override string ToString() { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<ItemGroup>
<Compile Include="System.Memory.Data.cs" />
</ItemGroup>
<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net5.0'))">
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\RequiresUnreferencedCodeAttribute.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)System.Text.Json\ref\System.Text.Json.csproj" />
</ItemGroup>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
Link="Common\System\Threading\Tasks\TaskToApm.cs" />
</ItemGroup>

<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net5.0'))">
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\RequiresUnreferencedCodeAttribute.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)System.Text.Json\src\System.Text.Json.csproj" />
</ItemGroup>
Expand Down
9 changes: 5 additions & 4 deletions src/libraries/System.Memory.Data/src/System/BinaryData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Threading;
Expand All @@ -17,6 +16,8 @@ namespace System
/// </summary>
public class BinaryData
{
private const string JsonSerializerRequiresUnreferencedCode = "JSON serialization and deserialization might require types that cannot be statically analyzed.";

/// <summary>
/// The backing store for the <see cref="BinaryData"/> instance.
/// </summary>
Expand All @@ -41,12 +42,12 @@ public BinaryData(byte[] data)
/// Creates a <see cref="BinaryData"/> instance by serializing the provided object to JSON
/// using <see cref="JsonSerializer"/>.
/// </summary>
///
/// <param name="jsonSerializable">The object that will be serialized to JSON using
/// <see cref="JsonSerializer"/>.</param>
/// <param name="options">The options to use when serializing to JSON.</param>
/// <param name="type">The type to use when serializing the data. If not specified, <see cref="object.GetType"/> will
/// be used to determine the type.</param>
[RequiresUnreferencedCode(JsonSerializerRequiresUnreferencedCode)]
public BinaryData(object? jsonSerializable, JsonSerializerOptions? options = default, Type? type = default)
{
type ??= jsonSerializable?.GetType() ?? typeof(object);
Expand Down Expand Up @@ -177,12 +178,11 @@ private static async Task<BinaryData> FromStreamAsync(Stream stream, bool async,
/// Creates a <see cref="BinaryData"/> instance by serializing the provided object using
/// the <see cref="JsonSerializer"/>.
/// </summary>
///
/// <typeparam name="T">The type to use when serializing the data.</typeparam>
/// <param name="jsonSerializable">The data to use.</param>
/// <param name="options">The options to use when serializing to JSON.</param>
///
/// <returns>A value representing the UTF-8 encoding of the JSON representation of <paramref name="jsonSerializable" />.</returns>
[RequiresUnreferencedCode(JsonSerializerRequiresUnreferencedCode)]
public static BinaryData FromObjectAsJson<T>(T jsonSerializable, JsonSerializerOptions? options = default)
{
byte[] buffer = JsonSerializer.SerializeToUtf8Bytes(jsonSerializable, typeof(T), options);
Expand Down Expand Up @@ -230,6 +230,7 @@ public override unsafe string ToString()
/// converted to.</typeparam>
/// <param name="options">The <see cref="JsonSerializerOptions"/> to use when serializing to JSON.</param>
/// <returns>The data converted to the specified type.</returns>
[RequiresUnreferencedCode(JsonSerializerRequiresUnreferencedCode)]
public T? ToObjectFromJson<T>(JsonSerializerOptions? options = default)
{
return JsonSerializer.Deserialize<T>(_bytes.Span, options);
Expand Down