public static void ApplyProblemDetailsDefaultsIfNeeded(object?value, int?statusCode) { if (value is ProblemDetails problemDetails) { ProblemDetailsDefaults.Apply(problemDetails, statusCode); } }
/// <summary> /// Initializes a new instance of the <see cref="Json"/> class with the values. /// </summary> /// <param name="value">The value to format in the entity body.</param> /// <param name="statusCode">The HTTP status code of the response.</param> /// <param name="jsonSerializerOptions">The serializer settings.</param> /// <param name="contentType">The value for the <c>Content-Type</c> header</param> internal JsonHttpResult(TValue?value, int?statusCode, string?contentType, JsonSerializerOptions?jsonSerializerOptions) { Value = value; JsonSerializerOptions = jsonSerializerOptions; ContentType = contentType; if (value is ProblemDetails problemDetails) { ProblemDetailsDefaults.Apply(problemDetails, statusCode); statusCode ??= problemDetails.Status; } StatusCode = statusCode; }
/// <summary> /// Creates a new <see cref="ProblemHttpResult"/> instance with /// the provided <paramref name="problemDetails"/>. /// </summary> /// <param name="problemDetails">The <see cref="ProblemDetails"/> instance to format in the entity body.</param> internal ProblemHttpResult(ProblemDetails problemDetails) { ProblemDetails = problemDetails; ProblemDetailsDefaults.Apply(ProblemDetails, statusCode: null); }