Skip to content
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

Add missing System.Net.Http.Json comments #92223

Merged
merged 2 commits into from
Sep 21, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static partial class HttpClientJsonExtensions
/// <param name="client">The client used to send the request.</param>
/// <param name="requestUri">The Uri the request is sent to.</param>
/// <param name="type">The type of the object to deserialize to and return.</param>
/// <param name="context">Source generated JsonSerializerContext used to control the deserialization behavior.</param>
/// <param name="context">The JsonSerializerContext used to control the deserialization behavior.</param>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically a JsonSerializerContext could have been manually extended by the user and not by a source generator, but I think the change is ok otherwise.

/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>The task object representing the asynchronous operation.</returns>
/// <exception cref="ArgumentNullException">The <paramref name="client"/> is <see langword="null"/>.</exception>
Expand All @@ -97,7 +97,7 @@ public static partial class HttpClientJsonExtensions
/// <param name="client">The client used to send the request.</param>
/// <param name="requestUri">The Uri the request is sent to.</param>
/// <param name="type">The type of the object to deserialize to and return.</param>
/// <param name="context">Source generated JsonSerializerContext used to control the deserialization behavior.</param>
/// <param name="context">The JsonSerializerContext used to control the deserialization behavior.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>The task object representing the asynchronous operation.</returns>
/// <exception cref="ArgumentNullException">The <paramref name="client"/> is <see langword="null"/>.</exception>
Expand All @@ -110,7 +110,7 @@ public static partial class HttpClientJsonExtensions
/// <typeparam name="TValue">The target type to deserialize to.</typeparam>
/// <param name="client">The client used to send the request.</param>
/// <param name="requestUri">The Uri the request is sent to.</param>
/// <param name="jsonTypeInfo">Source generated JsonTypeInfo to control the behavior during deserialization.</param>
/// <param name="jsonTypeInfo">The JsonTypeInfo used to control the deserialization behavior.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>The task object representing the asynchronous operation.</returns>
/// <exception cref="ArgumentNullException">The <paramref name="client"/> is <see langword="null"/>.</exception>
Expand All @@ -123,7 +123,7 @@ public static partial class HttpClientJsonExtensions
/// <typeparam name="TValue">The target type to deserialize to.</typeparam>
/// <param name="client">The client used to send the request.</param>
/// <param name="requestUri">The Uri the request is sent to.</param>
/// <param name="jsonTypeInfo">Source generated JsonTypeInfo to control the behavior during deserialization.</param>
/// <param name="jsonTypeInfo">The JsonTypeInfo used to control the deserialization behavior.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>The task object representing the asynchronous operation.</returns>
/// <exception cref="ArgumentNullException">The <paramref name="client"/> is <see langword="null"/>.</exception>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static partial class HttpClientJsonExtensions
/// <typeparam name="TValue">The target type to deserialize to.</typeparam>
/// <param name="client">The client used to send the request.</param>
/// <param name="requestUri">The Uri the request is sent to.</param>
/// <param name="jsonTypeInfo">Source generated JsonTypeInfo to control the behavior during deserialization.</param>
/// <param name="jsonTypeInfo">The JsonTypeInfo used to control the behavior during deserialization.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>An <see cref="IAsyncEnumerable{TValue}"/> that represents the deserialized response body.</returns>
/// <exception cref="ArgumentNullException">The <paramref name="client"/> is <see langword="null"/>.</exception>
Expand All @@ -80,7 +80,7 @@ public static partial class HttpClientJsonExtensions
/// <typeparam name="TValue">The target type to deserialize to.</typeparam>
/// <param name="client">The client used to send the request.</param>
/// <param name="requestUri">The Uri the request is sent to.</param>
/// <param name="jsonTypeInfo">Source generated JsonTypeInfo to control the behavior during deserialization.</param>
/// <param name="jsonTypeInfo">The JsonTypeInfo used to control the behavior during deserialization.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>An <see cref="IAsyncEnumerable{TValue}"/> that represents the deserialized response body.</returns>
/// <exception cref="ArgumentNullException">The <paramref name="client"/> is <see langword="null"/>.</exception>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient
/// <param name="client">The client used to send the request.</param>
/// <param name="requestUri">The Uri the request is sent to.</param>
/// <param name="value">The value to serialize.</param>
/// <param name="jsonTypeInfo">Metadata about the type to convert.</param>
/// <param name="jsonTypeInfo">The JsonTypeInfo used to control the behavior during serialization.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>The task object representing the asynchronous operation.</returns>
/// <exception cref="ArgumentNullException">The <paramref name="client"/> is null.</exception>
Expand All @@ -118,7 +118,7 @@ public static Task<HttpResponseMessage> PatchAsJsonAsync<TValue>(this HttpClient
/// <param name="client">The client used to send the request.</param>
/// <param name="requestUri">The Uri the request is sent to.</param>
/// <param name="value">The value to serialize.</param>
/// <param name="jsonTypeInfo">Metadata about the type to convert.</param>
/// <param name="jsonTypeInfo">The JsonTypeInfo used to control the behavior during serialization.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>The task object representing the asynchronous operation.</returns>
/// <exception cref="ArgumentNullException">The <paramref name="client"/> is null.</exception>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,18 @@ public static partial class HttpContentJsonExtensions
return ReadFromJsonAsAsyncEnumerableCore<TValue>(content, options, cancellationToken);
}

[RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)]
[RequiresDynamicCode(SerializationDynamicCodeMessage)]
private static IAsyncEnumerable<TValue?> ReadFromJsonAsAsyncEnumerableCore<TValue>(
HttpContent content,
JsonSerializerOptions? options,
CancellationToken cancellationToken)
{
var jsonTypeInfo = (JsonTypeInfo<TValue>)JsonHelpers.GetJsonTypeInfo(typeof(TValue), options);
return ReadFromJsonAsAsyncEnumerableCore(content, jsonTypeInfo, cancellationToken);
}

/// <summary>
/// Reads the HTTP content and returns the value that results from deserializing the content as
/// JSON in an async enumerable operation.
/// </summary>
/// <typeparam name="TValue">The target type to deserialize to.</typeparam>
/// <param name="content">The content to read from.</param>
/// <param name="jsonTypeInfo">The JsonTypeInfo used to control the deserialization behavior.</param>
/// <param name="cancellationToken"></param>
/// <returns>An <see cref="IAsyncEnumerable{TValue}"/> that represents the deserialized response body.</returns>
/// <exception cref="ArgumentNullException">
/// The <paramref name="content"/> is <see langword="null"/>.
/// </exception>
public static IAsyncEnumerable<TValue?> ReadFromJsonAsAsyncEnumerable<TValue>(
this HttpContent content,
JsonTypeInfo<TValue> jsonTypeInfo,
Expand All @@ -84,6 +85,17 @@ public static partial class HttpContentJsonExtensions
return ReadFromJsonAsAsyncEnumerableCore(content, jsonTypeInfo, cancellationToken);
}

[RequiresUnreferencedCode(SerializationUnreferencedCodeMessage)]
[RequiresDynamicCode(SerializationDynamicCodeMessage)]
private static IAsyncEnumerable<TValue?> ReadFromJsonAsAsyncEnumerableCore<TValue>(
HttpContent content,
JsonSerializerOptions? options,
CancellationToken cancellationToken)
{
var jsonTypeInfo = (JsonTypeInfo<TValue>)JsonHelpers.GetJsonTypeInfo(typeof(TValue), options);
return ReadFromJsonAsAsyncEnumerableCore(content, jsonTypeInfo, cancellationToken);
}

private static async IAsyncEnumerable<TValue?> ReadFromJsonAsAsyncEnumerableCore<TValue>(
HttpContent content,
JsonTypeInfo<TValue> jsonTypeInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,27 @@ private JsonContent(
Headers.ContentType = mediaType ?? JsonHelpers.GetDefaultMediaType();
}

/// <summary>
/// Creates a new instance of the <see cref="JsonContent"/> class that will contain the <paramref name="inputValue"/> serialized as JSON.
/// </summary>
/// <typeparam name="T">The type of the value to serialize.</typeparam>
/// <param name="inputValue">The value to serialize.</param>
/// <param name="mediaType">The media type to use for the content.</param>
/// <param name="options">Options to control the behavior during serialization, the default options are <see cref="JsonSerializerDefaults.Web"/>.</param>
/// <returns>A <see cref="JsonContent"/> instance.</returns>
[RequiresUnreferencedCode(HttpContentJsonExtensions.SerializationUnreferencedCodeMessage)]
[RequiresDynamicCode(HttpContentJsonExtensions.SerializationDynamicCodeMessage)]
public static JsonContent Create<T>(T inputValue, MediaTypeHeaderValue? mediaType = null, JsonSerializerOptions? options = null)
=> Create(inputValue, JsonHelpers.GetJsonTypeInfo(typeof(T), options), mediaType);

/// <summary>
/// Creates a new instance of the <see cref="JsonContent"/> class that will contain the <paramref name="inputValue"/> serialized as JSON.
/// </summary>
/// <param name="inputValue">The value to serialize.</param>
/// <param name="inputType">The type of the value to serialize.</param>
/// <param name="mediaType">The media type to use for the content.</param>
/// <param name="options">Options to control the behavior during serialization, the default options are <see cref="JsonSerializerDefaults.Web"/>.</param>
/// <returns>A <see cref="JsonContent"/> instance.</returns>
[RequiresUnreferencedCode(HttpContentJsonExtensions.SerializationUnreferencedCodeMessage)]
[RequiresDynamicCode(HttpContentJsonExtensions.SerializationDynamicCodeMessage)]
public static JsonContent Create(object? inputValue, Type inputType, MediaTypeHeaderValue? mediaType = null, JsonSerializerOptions? options = null)
Expand All @@ -47,16 +63,29 @@ public static JsonContent Create(object? inputValue, Type inputType, MediaTypeHe
return new JsonContent(inputValue, JsonHelpers.GetJsonTypeInfo(inputType, options), mediaType);
}

public static JsonContent Create<T>(T? inputValue, JsonTypeInfo<T> jsonTypeInfo,
MediaTypeHeaderValue? mediaType = null)
/// <summary>
/// Creates a new instance of the <see cref="JsonContent"/> class that will contain the <paramref name="inputValue"/> serialized as JSON.
/// </summary>
/// <typeparam name="T">The type of the value to serialize.</typeparam>
/// <param name="inputValue">The value to serialize.</param>
/// <param name="jsonTypeInfo">The JsonTypeInfo used to control the serialization behavior.</param>
/// <param name="mediaType">The media type to use for the content.</param>
/// <returns>A <see cref="JsonContent"/> instance.</returns>
public static JsonContent Create<T>(T? inputValue, JsonTypeInfo<T> jsonTypeInfo, MediaTypeHeaderValue? mediaType = null)
{
ThrowHelper.ThrowIfNull(jsonTypeInfo);

return new JsonContent(inputValue, jsonTypeInfo, mediaType);
}

public static JsonContent Create(object? inputValue, JsonTypeInfo jsonTypeInfo,
MediaTypeHeaderValue? mediaType = null)
/// <summary>
/// Creates a new instance of the <see cref="JsonContent"/> class that will contain the <paramref name="inputValue"/> serialized as JSON.
/// </summary>
/// <param name="inputValue">The value to serialize.</param>
/// <param name="jsonTypeInfo">The JsonTypeInfo used to control the serialization behavior.</param>
/// <param name="mediaType">The media type to use for the content.</param>
/// <returns>A <see cref="JsonContent"/> instance.</returns>
public static JsonContent Create(object? inputValue, JsonTypeInfo jsonTypeInfo, MediaTypeHeaderValue? mediaType = null)
{
ThrowHelper.ThrowIfNull(jsonTypeInfo);
EnsureTypeCompatibility(inputValue, jsonTypeInfo.Type);
Expand Down
Loading