@@ -69,22 +69,28 @@ protected void EnsureExpectedContentType(MediaTypeHeaderValue contentType, Media
6969 }}
7070}
7171
72- internal interface IResponse<T> where T : class
72+ /// <summary>
73+ /// Represents a response with content
74+ /// </summary>
75+ /// <typeparam name="T">Response</typeparam>
76+ internal interface IContent<T> where T : Response
7377{
7478 /// <summary>
75- /// Contents for this response
79+ /// Contents for the response
7680 /// </summary>
7781 internal static abstract ContentMediaType<T>[] ContentMediaTypes { get; }
7882}
7983
80- internal interface IContent<T> where T : class, IResponse<T>
81- {
82- internal static abstract ContentMediaType<T> ContentMediaType { get; }
83- }
84-
84+ /// <summary>
85+ /// Typed content media type
86+ /// </summary>
87+ /// <typeparam name="T">Response</typeparam>
8588internal readonly record struct ContentMediaType<T>(MediaTypeHeaderValue Value)
86- where T : class
89+ where T : Response
8790{
91+ /// <summary>
92+ /// Implicitly convert back to MediaTypeHeaderValue
93+ /// </summary>
8894 public static implicit operator MediaTypeHeaderValue(ContentMediaType<T> mediaType) => mediaType.Value;
8995}
9096
@@ -97,7 +103,7 @@ internal partial class Request
97103 /// <typeparam name="T">The response to match against</typeparam>
98104 /// <returns>True if a matched media type was found</returns>
99105 internal bool TryMatchAcceptMediaType<T>(
100- [NotNullWhen(true)] out ContentMediaType<T>? matchedContentMediaType) where T : class, IResponse <T>
106+ [NotNullWhen(true)] out ContentMediaType<T>? matchedContentMediaType) where T : Response, IContent <T>
101107 {
102108 var mediaTypes = T.ContentMediaTypes;
103109 var acceptHeaders = HttpContext.Request.GetTypedHeaders().Accept;
0 commit comments