GetSupportedContentTypes to take in declared and runtime type.
This commit is contained in:
parent
7448bf2843
commit
abf27d883f
|
|
@ -94,8 +94,9 @@ namespace Microsoft.AspNet.Mvc
|
||||||
foreach (var formatter in formatters)
|
foreach (var formatter in formatters)
|
||||||
{
|
{
|
||||||
var supportedContentTypes = formatter.GetSupportedContentTypes(
|
var supportedContentTypes = formatter.GetSupportedContentTypes(
|
||||||
GetObjectType(formatterContext),
|
formatterContext.DeclaredType,
|
||||||
contentType: null);
|
formatterContext.Object?.GetType(),
|
||||||
|
contentType: null);
|
||||||
|
|
||||||
if (formatter.CanWriteResult(formatterContext, supportedContentTypes?.FirstOrDefault()))
|
if (formatter.CanWriteResult(formatterContext, supportedContentTypes?.FirstOrDefault()))
|
||||||
{
|
{
|
||||||
|
|
@ -218,18 +219,5 @@ namespace Microsoft.AspNet.Mvc
|
||||||
|
|
||||||
return formatters;
|
return formatters;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Type GetObjectType([NotNull] OutputFormatterContext context)
|
|
||||||
{
|
|
||||||
if (context.DeclaredType == null || context.DeclaredType == typeof(object))
|
|
||||||
{
|
|
||||||
if (context.Object != null)
|
|
||||||
{
|
|
||||||
return context.Object.GetType();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return context.DeclaredType;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -20,12 +20,13 @@ namespace Microsoft.AspNet.Mvc
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a filtered list of content types which are supported by this formatter
|
/// Gets a filtered list of content types which are supported by this formatter
|
||||||
/// for the <paramref name="dataType"/> and <paramref name="contentType"/>.
|
/// for the <paramref name="declaredType"/> and <paramref name="contentType"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dataType">Type for which the supported content types are desired.</param>
|
/// <param name="declaredType">The declared type for which the supported content types are desired.</param>
|
||||||
|
/// <param name="instanceType">The runtime type for which the supported content types are desired.</param>
|
||||||
/// <param name="contentType">Content type for which the supported content types are desired.</param>
|
/// <param name="contentType">Content type for which the supported content types are desired.</param>
|
||||||
/// <returns>Content types which can are supported by this formatter.</returns>
|
/// <returns>Content types which are supported by this formatter.</returns>
|
||||||
IReadOnlyList<MediaTypeHeaderValue> GetSupportedContentTypes(Type dataType, MediaTypeHeaderValue contentType);
|
IReadOnlyList<MediaTypeHeaderValue> GetSupportedContentTypes(Type declaredType, Type instanceType, MediaTypeHeaderValue contentType);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines whether this <see cref="IOutputFormatter"/> can serialize
|
/// Determines whether this <see cref="IOutputFormatter"/> can serialize
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
return context.Object == null;
|
return context.Object == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyList<MediaTypeHeaderValue> GetSupportedContentTypes(Type dataType, MediaTypeHeaderValue contentType)
|
public IReadOnlyList<MediaTypeHeaderValue> GetSupportedContentTypes(Type declaredType, Type runtimeType, MediaTypeHeaderValue contentType)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Mvc
|
||||||
public IList<MediaTypeHeaderValue> SupportedMediaTypes { get; private set; }
|
public IList<MediaTypeHeaderValue> SupportedMediaTypes { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual IReadOnlyList<MediaTypeHeaderValue> GetSupportedContentTypes(Type dataType, MediaTypeHeaderValue contentType)
|
public virtual IReadOnlyList<MediaTypeHeaderValue> GetSupportedContentTypes(Type declaredType, Type runtimeType, MediaTypeHeaderValue contentType)
|
||||||
{
|
{
|
||||||
var mediaTypes = new List<MediaTypeHeaderValue>();
|
var mediaTypes = new List<MediaTypeHeaderValue>();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -550,7 +550,8 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyList<MediaTypeHeaderValue> GetSupportedContentTypes(Type dataType,
|
public IReadOnlyList<MediaTypeHeaderValue> GetSupportedContentTypes(Type declaredType,
|
||||||
|
Type runtimeType,
|
||||||
MediaTypeHeaderValue contentType)
|
MediaTypeHeaderValue contentType)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,8 @@ namespace Microsoft.AspNet.Mvc
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyList<MediaTypeHeaderValue> GetSupportedContentTypes(Type dataType,
|
public IReadOnlyList<MediaTypeHeaderValue> GetSupportedContentTypes(Type declaredType,
|
||||||
|
Type runtimeType,
|
||||||
MediaTypeHeaderValue contentType)
|
MediaTypeHeaderValue contentType)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,8 @@ namespace Microsoft.AspNet.Mvc.Core
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyList<MediaTypeHeaderValue> GetSupportedContentTypes(Type dataType,
|
public IReadOnlyList<MediaTypeHeaderValue> GetSupportedContentTypes(Type declaredType,
|
||||||
|
Type runtimeType,
|
||||||
MediaTypeHeaderValue contentType)
|
MediaTypeHeaderValue contentType)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ namespace ConnegWebsite
|
||||||
return contentType == null;
|
return contentType == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyList<MediaTypeHeaderValue> GetSupportedContentTypes(Type dataType, MediaTypeHeaderValue contentType)
|
public IReadOnlyList<MediaTypeHeaderValue> GetSupportedContentTypes(Type declaredType, Type runtimeType, MediaTypeHeaderValue contentType)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue